The final answer
Posted by danielmeyer on December 17, 2008
The story thus far:
The envers beforeCompletion() hook was not running when I switched from using Spring’s HibernateTransactionManager to using its JtaTransactionManager. I had done some digging on my own, then made a long post to the Spring Data Access forum (after an initial post to the envers forum).
The long post apparently scared everybody off ;) , so I wrote a much shorter, more focused post.
Note that for non-Spring JTA transactions, a JTA TransactionManagerLookup has to be specified in the Hibernate configuration.
On the trail of how to specify a TransactionManagerLookup, I found the
hibernate.transaction.manager_lookup_class setting in the Using JTA section of the Hibernate Reference Guide — but unbeknownst to me, another setting was needed…
- set hibernate.transaction.manager_lookup_class to a lookup strategy for your JEE container
- set hibernate.transaction.factory_class to org.hibernate.transaction.JTATransactionFactory
So, adding these two lines to my Hibernate spring beans file (lines 6 and 7 below) fixed the issue:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> ... <property name="hibernateProperties"> <props> ... <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> </props> </property> ... </bean>
NOW the envers beforeCompletion() hook gets called when using the JTA transaction manager.