rmonie wrote:
There are problems with the approach in the HIA book. Try the approach I posted in the wiki. We are using this successfully in several apps at the moment.
http://www.hibernate.org/318.htmlThis example does not have all supporting code supplied but should be enough to get you going. If you have problems let me know and i'll see if I can help.
cheers,
rob
Hi Rob,
I hope you don't mind my question so many months after your post (and that you're watching this thread).
I implemented and customized your audit interceptor yesterday as given at
http://www.hibernate.org/318.html.
It appears to be working well except for the crucial fact that the audit records saved in the postFlush() method aren't actually saved. In the logs I can see the correct SQL insert statements being generated, and the audit records themselves are correct when I log them.
At 318.html you mention
Quote:
you must use a different sessionFactory for your auditLogging than your usual DAOs. There is good discussion in other places about the reasons for this.
I've not been able to find any clear references or discussion on this topic in the Hibernate forum.
I've found this topic:
http://forum.hibernate.org/viewtopic.php?t=932065 where Christian says this:
christian wrote:
The most important thing about an Interceptor to remember is: you can't use the Session. But you can simply create a new temporary Session _on the same JDBC Connection_:
Session newSession = sessionFactory.openSession(oldSession.connection());
newSession....
newSession.flush();
newSession.close();
And I've found this thread:
http://forum.hibernate.org/viewtopic.php?t=955189 where the poster seems to be having the same problem, and there Steve directs suggests searching on the topic "transaction isolation".
I searched and read but found nothing that appears to help.
What is the actual way to get that session.save() in the postFlush() method to actually persist the data?
Or where are there threads which explain this a bit more indepth?
Many thanks,