I'm using hibernate-envers 4.2.21.FINAL, I added to some properties the annotation @Audit(withModifiedFlag = true). The AUD table is correctly created, the _MOD colums also, but each time I update an entity, all the _MOD colums have the flag set to true, even if I don't have updated any (or just some) of the properties.
Is this a bug? Or maybe a wrong hibernate configuration?
sql server, envers
No, I also tried to delete all the AUD tables to let the framework create them again from scratch.
I save the entity with session.saveOrUpdate(entity), and all the _MOD fields are flagged with "true".
I also noticed that envers is adding a revision each time I save an entity, even if I don't change any data. If it can help, I'm using spring and jsf.
My hibernate properties:
I'm debuggin the class org.hibernate.envers.event.EnversPostUpdateEventListenerImpl and in the following method
AuditWorkUnit workUnit = new ModWorkUnit(event.getSession(),event.getPersister().getEntityName(),getAuditConfiguration(),event.getId(),event.getPersister(),newDbState,event.getOldState());
event.getOldState is null, but in my opinion it should be not null. This is why envers add a new record to the AUD table.
Am I missing anything?
There are typically two reasons why the oldState array would be null:
Your entity is new (never persisted)
Your entity has been detached from the session and the update occurs outside it being managed.
If you could provide a minimal test case that replicates the problem I'll be happy to take a look.
Yes, i was about to update the jira. To retrieve the entity from jsf makes it detached, if I use merge instead of saveOrUpdate the properties are correctly set by envers.
Thanks for the help, you can close the jira!