Maybe you can try setting a breakpoint on AuditEventListener to see if the listener is invoked?
Yes, I tried to build a custom event listener that just does nothing but logs and delegates the call to AuditEventListener. The post-update method is being called. But the audit tables are not being updated !!
Do we need to add "EJB3Post...EventListener"s to the hibernate config file for the Envers persistance to work properly? If Yes, where and how should we add them?
Am I missing any transaction configuration settings in my hibernate.cfg.xml? Which transaction manager should I use for Envers to work?
I have added the transaction managers in the config file. This worked.
Now I get this error :
com.ibm.db2.jcc.c.SqlException: "IMGTEST.REVINFO" is an undefined name.
I dont know why it is going for IMGTEST schema when the default schema is defined as ROCC in the cofig file.
Is there any other attribute that I have to set to specify the schema for REVINFO table?
I think there's a bug with the revision entity not respecting the default schema setting.
Try creating a custom revision entity (there's an example in the doc, it can contain just the revision number and revision timestamp fields), and place an @Table annotation with the schema specified on it.
And you need transactions as you already found out for Envers to work, that's correct . Luckily you normally want transactions anyway
Thank You Adam ! That solved my issue. I have a created a custom Revision Entity and added it to my hibernate.cfg.xml.
I think this Revision Entity bug is happening only when you use the Hibernate Session factory instead of EntityManager. And also if you use hibernate from Spring using HibernateTemplate, we are not seeing this issue.
Here I have another question. If I close the session after inserting into the main table, the Envers is not doing the auditing saying THE SESSION IS ALREADY CLOSED. If I leave the session open without closing, the auditing is working.
So will ENVERS close the open session after inserting into the audit tables? If not, there willl be number of open sessions that are not closed !!