{code} final Session s = openSession(); s.getTransaction().begin(); final Project project = new Project(); project.setName( "fooName" ); project.setType( "fooType" ); s.persist( project ); s.getTransaction().commit(); s.clear(); for (int i = 0; i < 5; i++) { s.getTransaction().begin(); project.setName( "fooName" + i ); s.update( project ); s.getTransaction().commit(); s.clear(); } s.close();
...
public List getProjectRevisions(String property) { final Session s = openSession(); final AuditReader ar = AuditReaderFactory.get( s ); return ar.createQuery() .forRevisionsOfEntity(Project.class, false, true) .add(AuditEntity.property(property).hasChanged()) .getResultList(); }
...
demo.getProjectRevisions( "type" ); {code}
That will return *all* revisions, including the last 5 that solely updated the #name property. Calling Session#refresh prior to the Session#update is a workaround, as well as not clearing the Session after the add and each update. The issue appears to be limited to detached entities.
After discussing with [~adamw] & [~lukasz.antoniak], Lukasz suggested:
{quote} I had a closer look at the issue. The root cause is that Brett updates detached entities. In SinglePropertyMapper#mapModifiedFlagsToMapFromEntity(SessionImplementor, Map, Object, Object) we do not know the previous state of the entity. We would need to introduce pre-update listener and query database (if needed) to cache original state of the entity. Of course, the issue applies only to "modified flag" feature. {quote}
|