[ENVERS]: how to create a revision on parent entity if I update only a property on a child.
by Fabien PERIE
Hello,
Envers is a very good solution for auditing changes in your database and
the query Envers API is also very intuitive.
However, I have a case which doesn't work.
For information, I use the JBoss EAP server in version 6.3.3 (including
hibernate-core and hibernate-envers modules in version
4.2.21.Final-redhat-1).
I would like to have a revision on the parent entity if I update only a
property on a child.
On stackoverflow web site, this problem is mentioned:
*
http://stackoverflow.com/questions/27420161/envers-audits-parent-entity-w...
*
http://stackoverflow.com/questions/10121103/hibernate-envers-retrieving-t...
I'm looking for a better solution than the given one (to add a persistent
field containing the timestamp).
Now, is there an alternative solution ?
I tried to add a non persistent boolean property in my parent entity called
"forceUpdate", false by default.
In the subclass, before update, I set the forceUpdate property value to
true in the parent entity.
Next, via an hibernate interceptor, I wrote the following code:
@Override
public int[] findDirty(Object entity, Serializable id, Object[]
currentState, Object[] previousState,
String[] propertyNames, Type[] types)
{
int[] res = null;
if (entity instanceof IAuditChange)
{
final IAuditChange iac = (IAuditChange)entity;
if (iac.isForceUpdate())
{
res = new int[] { 1 };
}
}
return res;
}
This mechanism triggers the update in the parent entity but there is no
revision in the audit/envers table.
how to obtain a revision on parent entity if I update only a property on a
child ?
Thank's a lot for your answer,
Fabien
8 years, 8 months