"Local transaction already has 1 non-XA Resource: cannot add more resources" error

Posted by jthg on Stack Overflow See other posts from Stack Overflow or by jthg
Published on 2010-05-20T23:27:09Z Indexed on 2010/05/20 23:30 UTC
Read the original article Hit count: 383

Filed under:
|
|
|

After reading previous questions about this error, it seems like all of them conclude that you need to enable XA on all of the data sources. But:

  1. What if I don't want a distributed transaction? What would I do if I want to start transactions on two different databases at the same time, but commit the transaction on one database and roll back the transaction on the other?
  2. I'm wondering how my code actually initiated a distributed transaction. It looks to me like I'm starting completely separate transactions on each of the databases.

Info about the application:

The application is an EJB running on a Sun Java Application Server 9.1

I use something like the following spring context to set up the hibernate session factories:

<bean id="dbADatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/dbA"/>
</bean>

<bean id="dbASessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dbADatasource" />
    <property name="hibernateProperties">
        [hibernate properties...]
    </property>
    <property name="mappingResources">
        [mapping resources...]
    </property>
</bean>

<bean id="dbBDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/dbB"/>
</bean>

<bean id="dbBSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dbBDatasource" />
    <property name="hibernateProperties">
        [hibernate properties...]
    </property>
    <property name="mappingResources">
        [mapping resources...]
    </property>
</bean>

Both of the JNDI resources are javax.sql.ConnectionPoolDatasoure's. They actually both point to the same connection pool, but we have two different JNDI resources because there's the possibility that the two groups of tables will move to different databases in the future.

Then in code, I do:

sessionA = dbASessionFactory.openSession();
sessionB = dbBSessionFactory.openSession();
sessionA.beginTransaction();
sessionB.beginTransaction();

The sessionB.beginTransaction() line produces the error in the title of this post - sometimes. I ran the app on two different sun application servers. On one runs it fine, the other throws the error. I don't see any difference in how the two servers are configured although they do connect to different, but equivalent databases.

So the question is

  1. Why doesn't the above code start completely independent transactions?
  2. How can I force it to start independent transactions rather than a distributed transaction?
  3. What configuration could cause the difference in behavior between the two application servers?

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about ejb