-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SchemaUpdate exception with JTA "cannot set autocommit&
PostPosted: Tue Dec 19, 2006 4:04 pm 
Newbie

Joined: Tue Dec 19, 2006 3:28 pm
Posts: 1
Location: Greensboro, NC
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:


Top
 Profile  
 
 Post subject: Same here..
PostPosted: Mon Jan 01, 2007 8:59 pm 
Newbie

Joined: Wed Aug 03, 2005 2:13 am
Posts: 16
I'm having this exact same problem, trying to do a SchemaExport from a JTA transaction.

In my case it's while unit testing with embeddable EJB3.

Is there any workaround? I'm getting very close to modifying SchemaExport directly for myself so it doesn't set autocommit(true)...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 01, 2007 11:49 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
why don't you get the transaction from hibernate's Session instead of looking it up using JNDI?

remember that hibernate's transaction mechanism is an abstraction of different transaction environments, such as JNDI and JDBC.

I'm not sure but believe that solves the problem.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 12:37 am 
Newbie

Joined: Wed Aug 03, 2005 2:13 am
Posts: 16
I'm not getting a transaction from anywhere, this happens as part of the schema export, due to the hibernate.hbm2ddl.auto=create-drop property.

Also note that I'm using hibernate from EJB3 and not interacting directly with hibernate Sessions.

But the problem seems to have 'magically' disappeared for now..!

thanks,
D.

pasha wrote:
why don't you get the transaction from hibernate's Session instead of looking it up using JNDI?

remember that hibernate's transaction mechanism is an abstraction of different transaction environments, such as JNDI and JDBC.

I'm not sure but believe that solves the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.