• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Double transaction counts when using Hibernate Statistics

Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

A tiny monkey bit me and I got tiny ads:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic