withModifiedFlag set to true even if the property has not changed

Description

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?
Thanks

Environment

sql server, envers

Activity

Show:
Saul Giordani
February 23, 2017, 7:58 AM

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".

Saul Giordani
February 23, 2017, 9:17 AM

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:
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="org.hibernate.envers.track_entities_changed_in_revision">true</prop>
<prop key="org.hibernate.envers.store_data_at_delete">true</prop>

Saul Giordani
February 23, 2017, 9:29 AM

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?

Chris Cranford
February 23, 2017, 12:55 PM

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.

Saul Giordani
February 23, 2017, 1:06 PM

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!

Assignee

Unassigned

Reporter

Saul Giordani

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure