What I want to do: an insert, update or delete occurs for items I've marked with (my own) annotation @Auditable, and hibernate intercepts this and inserts,
as part of the same transaction, an entry in the audit table.
Problems:
- which is more suited, Interceptor or event listeners?
- how can I dig back from an interceptor to find its session, since I want to do session.save()?
- alternatively, I know I can get the session from some of the event listeners, is it legit to actually use that session to do inserts from inside an event handler?
- If I do the above, will I be inserting into the same transaction as the one in which I did the session.save(auditable) ?
- What's the distinction between PersistEventListener and SaveOrUpdateEventListener? How can I tell an insert from an update in event listeners?
Could anyone please help me out with these? The reference docs on this area of Hibernate are a tad sparse.