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!
subject: Double transaction counts when using Hibernate Statistics