-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate + c3p0 + committing transactions
PostPosted: Thu Jul 20, 2006 4:32 pm 
Newbie

Joined: Wed Sep 01, 2004 1:38 pm
Posts: 5
Location: Saint Paul, MN
I'm facing a mystifying problem that I assume is my fault and simple to solve, I just can't seem to find it.

For various reasons we're switching from the Hibernate mbean (com.code42.hibernate.jmx.HibernateService) to a configuration based upon hibernate.cfg.xml that uses c3p0. All of the configuration parameters have been moved over to the new file, the mbean config has been removed, c3p0 is starting properly, and everything looks just great EXCEPT committing (or rolling back) transactions. When our code calls commit JTATransaction apparently receives the command but the database shows no sign of it in the log.

Instead of a 'commit' which mysteriously doesn't appear, the connection is closed, checked back into c3p0, and the pool does its rollback when it gets the connection back (default behavior).

I've debugged the code both in the new environment and old and verified that JTATransaction.commit() is called normally and the line 'ut.commit();' IS executed. However, stepping over the line shows no entry in the debug log in my new environment. This issue has also been replicated with the latest c3p0 (.9+) and postgresql.

Any ideas would be appreciated, thank you!

Hibernate version: 3.0.3
c3p0 version: 0.8.5.2
jboss version: 3.2.5

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: MySQL 4.1

Debug level Hibernate log excerpt: This is what JTATransaction sees when commit is called:
DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] post flush
DEBUG [org.hibernate.transaction.JTATransaction] commit
DEBUG [org.hibernate.transaction.CacheSynchronization] transaction before completion callback
DEBUG [org.hibernate.jdbc.JDBCContext] before transaction completion
DEBUG [org.hibernate.impl.SessionImpl] before transaction completion
DEBUG [org.hibernate.transaction.CacheSynchronization] transaction after completion callback, status: 3
DEBUG [org.hibernate.jdbc.JDBCContext] after transaction completion
DEBUG [org.hibernate.impl.SessionImpl] after transaction completion
DEBUG [org.hibernate.transaction.JTATransaction] Committed JTA UserTransaction

MySQL log excerpt: This is what the database log shows. The 'rollback' comes from c3p0 reclaiming the connection. There is no commit command?
060720 14:25:24 308 Execute [29] [my last sql command in the tx]
060720 14:25:41 308 Query rollback
308 Query SET autocommit=1


hibernate.cfg.xml excerpt:
<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>

<!-- properties -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">false</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="jta.UserTransaction">UserTransaction</property>
<property name="connection.username">remon</property>
<property name="connection.password">re2005</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/jn_head</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>

<property name="hibernate.connection.release_mode">on_close</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.jdbc.use_scrollable_resultset">false</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.fetch_size">0</property>

<!-- mapping files -->
. . . [removed]
</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 6:20 pm 
Newbie

Joined: Wed Sep 01, 2004 1:38 pm
Posts: 5
Location: Saint Paul, MN
I believe I've found it. In the hibernate docs:

"JDBC connections obtained from a JNDI datasource will automatically participate in the container-managed transactions of the application server."

We had removed the jboss datasource in an attempt to connect to the db outside of and inside of jboss the same way, but it looks like the hibernate-configured connections don't participate within the jboss transactions. I put the datasource back, left the mbean off, hooked hibernate to the datasource through jndi and the problem went away.

Not perfect yet, but understandable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.