2 Replies Latest reply on Aug 12, 2011 10:13 AM by jeha

    Transaction management w/ Hibernate 2lc and Glassfish

    meetoblivion

      Hey there

       

      So I'm trying to configure hibernate w/ infinispan as the 2lc on a glassfish based application.  In general, everything works fine, except when I try to load an entity, modify then save it in a single method call.  I get the following in my stack trace:

       

      Caused by: org.infinispan.CacheException: java.lang.IllegalStateException: Local transaction already has 1 non-XA Resource: cannot add more resources. 
          at org.infinispan.transaction.xa.TransactionTable.getOrCreateXaAdapter(TransactionTable.java:186)
          at org.infinispan.interceptors.TxInterceptor.enlist(TxInterceptor.java:196)
          at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:178)
          at org.infinispan.interceptors.TxInterceptor.visitPutKeyValueCommand(TxInterceptor.java:132)
          at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
          at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
          at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:57)
          at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:38)
          at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)
          at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
          at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
          at org.infinispan.interceptors.BatchingInterceptor.handleDefault(BatchingInterceptor.java:76)
          at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)
          at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
          at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:273)
          at org.infinispan.CacheDelegate.put(CacheDelegate.java:429)
          at org.infinispan.CacheSupport.put(CacheSupport.java:28)
          at org.hibernate.cache.infinispan.util.CacheAdapterImpl.put(CacheAdapterImpl.java:96)

       

      My configuration looks like this:

       

      persistence.xml

       

      <property name="hibernate.cache.use_second_level_cache" value="true"/>
            <property name="hibernate.cache.use_query_cache" value="true"/>
            <property name="hibernate.cache.region.factory_class"
            value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
            <property name="hibernate.cache.infinispan.cfg" value="jpa-cache.xml"/>
            <!-- If using to JPA, add to your persistence.xml -->

       

            <property name="hibernate.transaction.factory_class"
            value="org.hibernate.transaction.JTATransactionFactory"/>
            <property name="hibernate.transaction.manager_lookup_class"
            value="org.hibernate.transaction.SunONETransactionManagerLookup"/>

       

      in my infinispan configuration

       

      <transaction 
            transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
            syncRollbackPhase="false"
            syncCommitPhase="false"
            useEagerLocking="false"/>
      <invocationBatching enabled="true"/>

       

      Any idea?

        • 1. Re: Transaction management w/ Hibernate 2lc and Glassfish
          galder.zamarreno

          John, what Infinispan version are you using? Can you try with latest 4.2.0.Final?

           

          Even though I don't have the exact source code, it seems to me that the exception comes from the TM itself, can u show the entire stacktrace including the botton-most exception?

           

          Finally, you shouldn't add transaction element to your configuration and definitely have no invocation batching. Please read http://community.jboss.org/wiki/UsingInfinispanasJPAHibernateSecondLevelCacheProvider#JTA_Transactions_Configuration section carefully, there's no need for you to fiddle with the Infinispan transaction configuration cos Hibernate 2LC code plugs in the transaction manager you configured in Hibernate.

          • 2. Re: Transaction management w/ Hibernate 2lc and Glassfish
            jeha

            John, did you configure your other resources for XA?

             

            Your post is quite old, but I just had the same problem and for me the solution was to set all db pools (MySQL) to XA:

            - jdbc-connection-pool => datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"

            - jdbc-connection-pool => res-type="javax.sql.XADataSource"

            and of course JMS:

            - connector-connection-pool => transaction-support="XATransaction"

             

            I debugged into org.infinispan.interceptors.TxInterceptor and looked at the transaction before throwing the CacheException. The "1 non-XA" resource was the JDBC DS for me. Maybe debugging is a good idea for you too.

             

            (btw, I use version 4.2.1.FINAL together with Hibernate 3.4 - yes 3.4)