6 Replies Latest reply on Feb 3, 2015 7:11 PM by matt_madhavan

    Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!

    matt_madhavan

      Hello,

      I am having a strange problem while running a camel application as a We application inside Wildfly. I have two transactional resources. JPA (Hibernate) and JMS (ActiveMQ). The Datasource is a XA datasource backed by Oracle. When an execution completes (a route executes) a SQL Exception.

       

      Caused by: java.sql.SQLException: You cannot commit with autocommit set!

          at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:1068)

          at org.jboss.jca.adapters.jdbc.WrappedConnection.commit(WrappedConnection.java:758)

          at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112) [hibernate-core-4.2.1.Final.jar:4.2.1.Final]

       

      However if I run the same application with Atomikos JTA Transaction Manager it work fine.

       

      The following is the trace when I run the application with Atomikos JTA.

      9:25:16,369 INFO  [stdout] (default task-8) 19:25:16.369 [default task-8] TRACE o.s.t.jta.JtaTransactionManager - Triggering beforeCommit synchronization

       

      19:25:16,369 INFO  [stdout] (default task-8) 19:25:16.369 [default task-8] TRACE o.s.t.jta.JtaTransactionManager - Triggering beforeCompletion synchronization

       

      19:25:16,370 INFO  [stdout] (default task-8) 19:25:16.370 [default task-8] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization@99b0185] for key [org.hibernate.ejb.EntityManagerImpl@3e9488b4] from thread [default task-8]

       

      19:25:16,370 INFO  [stdout] (default task-8) 19:25:16.370 [default task-8] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.orm.jpa.EntityManagerHolder@25c7c9e3] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c87227b] from thread [default task-8]

       

      19:25:16,371 INFO  [stdout] (default task-8) 19:25:16.371 [default task-8] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.jms.connection.JmsResourceHolder@53ccb3a5] for key [org.apache.activemq.pool.XaPooledConnectionFactory@2d72da5b] from thread [default task-8]

       

      19:25:16,372 INFO  [stdout] (default task-8) 19:25:16.372 [default task-8] DEBUG o.s.t.jta.JtaTransactionManager - Initiating transaction commit

       

      19:25:16,374 INFO  [stdout] (default task-8) 19:25:16.374 [default task-8] INFO  c.a.i.imp.CompositeTransactionImp - commit() done (by application) of transaction 10.10.50.205.tm0000100001

       

      19:25:16,375 INFO  [stdout] (default task-8) 19:25:16.375 [default task-8] TRACE o.s.t.jta.JtaTransactionManager - Triggering afterCommit synchronization

       

      19:25:16,377 INFO  [stdout] (default task-8) 19:25:16.377 [default task-8] TRACE o.s.t.jta.JtaTransactionManager - Triggering afterCompletion synchronization

       

      19:25:16,377 INFO  [stdout] (default task-8) 19:25:16.377 [default task-8] TRACE o.s.t.s.TransactionSynchronizationManager - Clearing transaction synchronization


      But when I run the application with Wildfly JTA TransactionManager I am getting the following trace!


      19:45:44,320 INFO  [stdout] (default task-9) 19:45:44.320 [default task-9] TRACE o.s.t.jta.JtaTransactionManager - Triggering beforeCommit synchronization

       

      19:45:44,321 INFO  [stdout] (default task-9) 19:45:44.321 [default task-9] TRACE o.s.t.jta.JtaTransactionManager - Triggering beforeCompletion synchronization

       

      19:45:44,321 INFO  [stdout] (default task-9) 19:45:44.321 [default task-9] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization@f1dc844] for key [org.hibernate.ejb.EntityManagerImpl@4ed3403a] from thread [default task-9]

       

      19:45:44,321 INFO  [stdout] (default task-9) 19:45:44.321 [default task-9] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.orm.jpa.EntityManagerHolder@35901897] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@15711eb3] from thread [default task-9]

       

      19:45:44,322 INFO  [stdout] (default task-9) 19:45:44.322 [default task-9] TRACE o.s.t.s.TransactionSynchronizationManager - Removed value [org.springframework.jms.connection.JmsResourceHolder@26e77d94] for key [org.apache.activemq.pool.XaPooledConnectionFactory@66471c30] from thread [default task-9]

       

      19:45:44,323 INFO  [stdout] (default task-9) 19:45:44.323 [default task-9] DEBUG o.s.t.jta.JtaTransactionManager - Initiating transaction commit

       

      19:45:44,324 INFO  [stdout] (default task-9) 19:45:44.324 [default task-9] TRACE o.s.t.jta.JtaTransactionManager - Triggering afterCommit synchronization

       

      19:45:44,325 INFO  [stdout] (default task-9) 19:45:44.325 [default task-9] TRACE o.s.t.jta.JtaTransactionManager - Triggering afterCompletion synchronization

       

      19:45:44,326 INFO  [stdout] (default task-9) 19:45:44.326 [default task-9] TRACE o.s.t.s.TransactionSynchronizationManager - Clearing transaction synchronization

       

      19:45:44,326 INFO  [stdout] (default task-9) 19:45:44.326 [default task-9] WARN  o.a.c.s.spi.TransactionErrorHandler - Transaction rollback (0x3d63fab) redelivered(unknown) for (MessageId: ID-NCDB5956-22-57628-1422668721782-0-1 on ExchangeId: ID-NCDB5956-22-57628-1422668721782-0-2) caught: Error while committing the transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction

       

      .....

      Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection

          at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:116) [hibernate-core-4.2.1.Final.jar:4.2.1.Final]

          at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:178) [hibernate-core-4.2.1.Final.jar:4.2.1.Final]

          ... 76 more

      Caused by: java.sql.SQLException: You cannot commit with autocommit set!

          at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:1068)

          at org.jboss.jca.adapters.jdbc.WrappedConnection.commit(WrappedConnection.java:758)

          at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112) [hibernate-core-4.2.1.Final.jar:4.2.1.Final]

       


       

      Any ideas please? I have been stuck on this problem for a while!

      Please note that, I dis my google research  have played with the Hibernate settings etc, but to no avail!

       

      Thanks

      Matt

        • 1. Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
          smarlow

          Sounds like the root issue is that the wrong Hibernate transaction integration class is in use, such that Hibernate is not aware of the WildFly JTA transaction manager (active) transaction.  This might be a matter of configuring a different Spring transaction factory. 

          • 2. Re: Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
            matt_madhavan

            Hi Scott,

            The following is my configuration. Please note that the same hibernate configuration works for Atmimikos Transaction Manager and Bitronix. Just not JBoss JTA.

             

            Any ideas please?

             

            Thanks

            Matt

             

            @Bean(name = "transactionManager")
            public PlatformTransactionManager transactionManager() {
              
               JtaTransactionManager transactionManager = new org.springframework.transaction.jta.JtaTransactionManager ();
               transactionManager.setTransactionManager (jbossTransactionManager() );
               transactionManager.setUserTransaction (jbossUserTransaction () );
                return transactionManager;
            }
            Properties additionalProperties() {
                return new Properties() {
                    {  // Hibernate Specific: org.hibernate.service.jta.platform.spi.JtaPlatform
                        setProperty("hibernate.hbm2ddl.auto", env.getProperty("database.hibernate.schema_update"));
                        setProperty("hibernate.dialect", env.getProperty("database.hibernate.dialect"));
                        setProperty("hibernate.show_sql", env.getProperty("database.hibernate.show_sql"));
                        setProperty("hibernate.format_sql", env.getProperty("database.hibernate.format_sql"));
                        setProperty("hibernate.ejb.naming_strategy", env.getProperty("database.hibernate.ejb.naming_strategy"));
                        setProperty("hibernate.use_sql_comments", env.getProperty("database.hibernate.use_sql_comments"));
                      
            //            setProperty("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform");
            //            setProperty("hibernate.transaction.factory_class", "org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory");

             

                        setProperty("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");
                        setProperty("hibernate.connection.autocommit", "false");
                      
            //            setProperty("hibernate.connection.autocommit", "false");
            //            setProperty("org.hibernate.service.jta.platform.spi.JtaPlatform", "org.hibernate.transaction.JBossTransactionManagerLookup");
            //            setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");
            //            //setProperty("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");
                     }
                };
            }
            • 3. Re: Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
              smarlow

              I haven't worked through this myself but others have.  Try this stackoverflow link.

              • 4. Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
                matt_madhavan

                Hello,

                Anybody out there please?

                 

                Thanks

                Matt

                • 5. Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
                  smarlow

                  See my previous answer (mentions that org.springframework.transaction.jta.JtaTransactionManager shouldn't be used and that you should instead use org.springframework.orm.hibernate4.HibernateTransactionManager), there are plenty of eyes on this forum but other Spring users might not be as quick to respond.

                  • 6. Re: Re: Poblem using Wildfly's JTA TransactionManager - You cannot commit with autocommit set!
                    matt_madhavan

                    HI Scott,

                    I think I just figured out - (a rather silly but very obvious from the exception log.). I am still testing.

                     

                    @Bean(name = "entityManagerFactory")

                        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

                       LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
                       emf.setDataSource(dataSource());

                     

                    The datesource should have been

                    emf.setJtaDataSource(dataSource()); and not emf.setDataSource(dataSource());


                    Please note the JTA.


                    First time I am using complete Spring Java configuration even for persistence.xml and I messed it up. I looked at one of my old persitence.xml and it was right then obvious!


                    Looks like Atomikos is moe tolerant than JBoss JTA. It just logs and continues where is JBoss JTA throws a really ugly exception which is good!


                    Thanks for your input and time!


                    Matt'M


                    NB: I have posted a question on ActiveMQ and Managed connections. Can you please take a look at it?