3 Replies Latest reply on Dec 21, 2007 11:40 AM by Adrian Brock

    "Can't call rollback when autocommit=true" problem with JBos

    Advait Newbie

      Hi All,
      I am running JBoss 4.2.1.GA and mysql-connector-java-5.0.3. I am having this ds file:

      <datasources>
       <local-tx-datasource>
       <jndi-name>MyDS</jndi-name>
       <connection-url>jdbc:mysql://localhost:4306/myds?autoReconnect=true</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>***</user-name>
       <password>***</password>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <dialect>org.hibernate.dialect.MySQLDialect</dialect>
       </local-tx-datasource>
      </datasources>
      
      


      my hibernate.cfg.xml
      <hibernate-configuration>
       <session-factory>
       <property name="connection.datasource">java:MyDS</property>
       <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
       <!--
       <property name="hibernate.current_session_context_class">thread</property>
       -->
       <property name="hibernate.connection.release_mode">after_transaction</property>
       <mapping resource="UserInfo.hbm.xml" />
       </session-factory>
      </hibernate-configuration>
      


      this is how i retrieve SessionFactory:
      public static SessionFactory getSessionFactory() {
      Configuration conf = new Configuration().configure();
       return conf.buildSessionFactory();
      }
      


      this is how i use hibernate session:
      session =sessionFactory.openSession();
      session.beginTransaction();
      session.save(userInfo);
      session.getTransaction().commit();
      


      I get this excpetions when i try to get session factory:
      2007-12-18 11:29:04,090 WARN [org.jboss.resource.connectionmanager.TxConnectionManager] Connection error occured: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@19ae30e[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@10b8754 handles=0 lastUse=1197957541349 permit=true trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@567b79 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@1c44935 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1e1aab1 txSync=null]
      com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Can't call rollback when autocommit=true
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
       at com.mysql.jdbc.Connection.rollback(Connection.java:5041)
       at org.jboss.resource.adapter.jdbc.local.LocalManagedConnection.rollback(LocalManagedConnection.java:86)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.tidyup(TxConnectionManager.java:683)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.returnManagedConnection(BaseConnectionManager2.java:353)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:639)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.closeHandle(BaseWrapperManagedConnection.java:266)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.close(WrappedConnection.java:129)
       at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:74)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
       at com.mphasis.mframeopen.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:12)
       at com.mphasis.mframeopen.webmetrics.dao.AddUserInfoDAO.getHibernateSessionFactory(AddUserInfoDAO.java:12)
      
      


        • 1. Re:
          Vicky Kak Master

          I don't see this an JCA problem , looks like you are missing something in hibernate misconfiguration . Can you look for that ?

          • 2. Re:
            jaikiran pai Master

            Your hibernate.cfg.xml contains:

            <property name="connection.datasource">java:MyDS</property>


            Change it to


            <property name="hibernate.connection.datasource">java:MyDS</property>


            See if that works.


            • 3. Re:
              Adrian Brock Master

              1) Don't use autoreconnect


              autoReconnect=true


              This breaks transactions. A reconnect looses all the state.

              2) Why are you defining a local-tx datasource then handling the transaction yourself?
              Looks very confused to me. no-tx-datasource perhaps if want to do everything
              yourself?

              3) "thread" session context is just "broken" if you in an appserver/using JTA/CMT/BMT.
              It simply doesn't understand transaction demarcation (see the FAQ)
              and [url]http://www.hibernate.org/42.html[url]

              4) You should also be using "AFTER_STATEMENT" release mode
              http://www.hibernate.org/hib_docs/reference/en/html/transactions.html
              since the appserver's connection manager already does the necessary
              caching of the connection and also understands when to (not) cache better
              than hibernate when crossing transaction boundaries.