We're updating the issue view to help you get more done. 

Hibernate-Envers has incoherent behavior for modified flag when create new Entity

Description

When creating a new Entity and then inserting her in the associated table, the values of the modified flag (column that can be added with org.hibernate.envers.global_with_modified_flag = true ) are unpredictibles.

When you persist the entity at the end of the modification simply like this :

1 2 3 4 5 6 7 Entite entite = new Entite(); entite.setId("xxxxxxxxxxxx"); entite.setDate(new Date()); entityManager.persist(entite);

The principle seem to be this one :

  • each property that is fill with some value get a modified flag to true, every property that remain null get a false modified flag (so here date_mod = true)

But if in the same transaction, you make some changes after the persist's call, like this :

1 2 3 4 5 6 7 8 9 10 11 Entite entite = new Entite(); entite.setId("xxxxxxxxxxxx"); entite.setDate(new Date()); entityManager.persist(entite); entite.setSecondField("Hello"); entityManager.merge(entite);

Than it's like the modifications made before the persist are forgotten, and Hibernate-Envers apply the precedent principle only to the changes made between the persist and the update.

So we get date_mod = false , and second_field_mod = true.

It would be nice to have a coherent behavior on the whole changes that are made inside one transaction, and so that the precedent principle be applied to every changes.

Thx

Environment

Hibernate 5.1, Postgresql, Spring

Status

Assignee

Chris Cranford

Reporter

Philippe

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.5
5.0.12
5.2.9

Priority

Major