I've read the various suggested documents, searched the forum and done google searching but this problem is still haunting us.
Note: when I say JDBC as opposed to JTA I mean we're using Hibernate's Transaction API with its JDBC transaction support. When I say JTA I mean we're using its JTA transaction support and UserTransaction usage.
* We use JTA with Hibernate in JBoss 4.0.5 GA
* We use JDBC with Hibernate for unit testing in JUnit
We have different configuration files for the testing environment and the server environment.
Everything works fine in the testing environment (and fine in the server environment if we use JDBC instead of JTA).
The server has issues when doing a SchemaUpdate. When we first use a transaction after the server startsup Hibernate connects to the DB and attempts to update the schema (which we want).
This creates the problem documented various places: SchemaUpdate calls
Code:
connectionHelper.prepare(true);
Which tries to set the auto commit value. This throws the exception you see below in the stack trace.
How are we supposed to get around Hibernate's SchemaUpdate always attempting something that causes an exception?
Is it impossible to do a SchemaUpdate while using JTA transactions?
The server functions afterword so it's just the failing SchemaUpdate that is troublesome.
The basic parts of the 2 config files are:
JDBC version:
<property name="connection.url">jdbc:mysql://@dbHost@:@dbPort@/referralpro</property>
<property name="connection.username">@dbUsername@</property>
<property name="connection.password">@dbPassword@</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
JTA version:
<property name="connection.datasource">java:/ReferralProDS</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<property name="use_outer_join">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="current_session_context_class">jta</property>
<!--
<property name="current_session_context_class">org.hibernate.context.JTASessionContext</property>
-->
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
Hibernate version: 3.2.0.ga
Mapping documents:
Code between sessionFactory.openSession() and session.close():
try {
UserTransaction tx = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
tx.begin();
factory.getCurrentSession().load(...);
tx.commit();
}
catch (RuntimeException e) {
tx.rollback();
throw e;
}
Full stack trace of any exception that occurs:
ERROR [ SchemaUpdate]
(http-0.0.0.0-8080-1) Error closing connection
java.sql.SQLException: You cannot set autocommit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcA
utoCommit(BaseWrapperManagedConnection.java:482)
at org.jboss.resource.adapter.jdbc.WrappedConnection.setAutoCommit(Wrapp
edConnection.java:322)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper
.release(SuppliedConnectionProviderConnectionHelper.java:49)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:173
)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
311)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1213)
Name and version of the database you are using:
MySQL-5.0.27-community-nt
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: