First posted from the Hibernate Envers community forum:
Hibernate Envers setup with 'store_data_at_delete' = 'true' in order to provide an additional revision when an entity is deleted. In Hibernate 4.2.1.Final, when a mapping entity is deleted, Hibernate Envers attempts to insert a deletion revision record into the appropriate audit table, but does not populate the insert statement with the id of the entity that is being deleted.
The delete revision record was not being inserted at all in Hibernate 4.1.12.Final, but after viewing HHH-8087 Closed and upgrading, this issue was observed.
The use case I had was the following with all entities having an @Audited annotation.
- User table - User metadata
- User group table - User group metadata. Deleting a user group deletes all user group member associations via cascade.
- User group member table - A mapping table to associate users to one or more user groups.
1. Create user
2. Create user group
3. Add user to user group (Envers inserts an 'ADD (0)' revision for user group member.)
4. Delete user group which also cascades to delete associated user group member records (Envers inserts a 'DEL (2)' revision for user group member with no user group member id.
The user group member audit table schema is below...
The hibernate log shows as follows as the insert is done with no id. The db constraint prevents the insertion due to the not null constraint on the audit table id column.