This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Double transaction counts when using Hibernate Statistics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Double transaction counts when using Hibernate Statistics" Watch "Double transaction counts when using Hibernate Statistics" New topic

Double transaction counts when using Hibernate Statistics

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
I am getting a double count of transactions when using Hibernate Statistics.

The double transaction counting is happening within Hibernate's JDBCContext class. JDBCContext.afterTransactionCompletion() is called after the transaction is completed, which results in an increment of the statistics' transaction count, and then this method is called again in JDBCContext.connectionCleanedUp() as a result of a isTransactionalCallbackRegistered flag not being set, resulting in the second increment of the transaction count statistics value. It seems that the JDBCContext's isTransactionalCallbackRegistered flag is set in the registerSynchronizationIfPossible() method if registering synchronization with a JTA TransactionManager, and because I'm using a HibernateTransactionManager in my test this flag never gets set to true.

In short it appears that the transaction count gets incremented when the transaction completes and then again when the session is cleaned up if you're not using a JTA TransactionManager. I'm not sure if this is the desired behavior or a bug, as I don't understand this code very well.

My test is an extension of Spring's AbstractTransactionalDataSourceSpringContextTests, which opens a single transaction which is rolled back at the completion of the test. I assume that I should see one transaction in the Hibernate statistics summary I display at the end of my test, but instead I see two.

If anyone has seen this before, or knows something about it which would enlighten me then I'd certainly appreciate your response. Thanks in advance!

wood burning stoves
subject: Double transaction counts when using Hibernate Statistics
Similar Threads
Stateless SB and Synchronization
Spring transaction management with listeners
spring: different Transaction issolation levels using programatic transaction
Hibernate Transactions -- JTA and CMT
JTA Transaction doesn't rollback Hibernate sessions