Does HibernateTemplate work with Envers? If so, how?

BernateTemplate has its JPA counterpart JpaTemplate which provides a fairly similar functionality.

BernateTemplate has its JPA counterpart, JpaTemplate which provides a fairly similar functionality. The reason Envers doesn't work with bernateTemplate is because it relies on JPA events (you can see the listeners declared in your persistence. Xml above) triggered when EntityManager is used.It's possible in theory to write code to trigger those events from bernate session when bernateTemplate is used, but it's rather involved.

Excellent - using JpaTemplate should do the trick then. It does not have all the bells and whistles that I want (in particular, I had some code that needs to do pagination, and did that via findByCriteria, which allows one to inject limits on the call), but at least I have a starting point. Thank you!

– chester Oct 30 '09 at 17:23 This is somewhat of a hack, but if you set JpaTemplate's exposeNativeEntityManager to true, you can use its executeFind() method to cast EntityManager passed to JpaCallback as bernateEntityManager and use getSession() of the latter to do criteria-based queries. – ChssPly76 Oct 30 '09 at 18:07 Also, in Envers 1.2.1 (the latest release) AuditEventListener implements regular bernate's event listeners which means it actually should be possible to configure it for plain You'd need to get rid of the entityManagerFactory and your persistence. Xml and instead configure all the listeners as part of sessionFactory using eventListeners map - look at LocalSessionFactoryBean for details; you'd then be able use Note that I have not tested this.

– ChssPly76 Oct 30 '09 at 18:12 Hmmm.... gotta check both approaches. I think that if I really need to use I'd rather drop JPA altogether, but I'll try first to do it all without either exposing the bernateEntityManager or trying such a new funcionality. Thanks.

– chester Nov 1 '09 at 14:47.

All you needed to do was put @Transactional in your Dao or services which call the dao.save()/ update methods. Even if you register your eventlistener these events are not fired unless you use transcational of the Spring FW. Spring has to know and tell hibernate that these events are fired.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions