We use a multi-column unique constraint and a version tag for optimistic locking. For some columns we want to detect changes and generate entries in other table.
So the setup is following: *.hbm.xml {code:xml} <class name="anyClass" table="any_class"> <id name="id" column="id" type="long" unsaved-value="0"> <!-- removed --> </id> <version type="timestamp" column="changed" name="changed" access="property" unsaved-value="null" /> <properties name="uniqueConst" unique="true"> <property name="first" type="string" length="70" /> <property name="secound" column="secound" type="string" length="25" /> </properties> <property name="normalProp" column="normal" type="string" length="25"/> </class> {code}
And we register and implement a {{PreUpdateEventListener}}. This listener will compare old and new values. And will create a new record for every change.
We achive this by getting the state via:
{code:java} Object old oldObj = ((PreUpdateEvent)inEvent).getOldState(); Object new newObj = ((PreUpdateEvent)inEvent).getState();}} {code}
So our testcase: {code:java}AnyClass any = ourDao.getAnyClass(); any.setFirst("blabla"); assertEquals(2, ourDao().listAudit().size()); {code}
In Hibernate 4.3.11 we get 2 changes. In Hibernate 5.0.7 we get 1 change.
So what happens? One change cannot be detected, because our {{timestamp}} property only changes in Hibernate 4.3.11? But if we touch {{normalProp}} everything works as expected. I assume changes in a property grouped by properties aren't detected, resp. the dirty flag isn't set. |
|