I have a parent class with set of one-to-many children class mapping:
Code:
<class name="parentClass" table="parent_table" optimistic-lock="version">
...
<set name="children" lazy="true" inverse="true" cascade="delete">
<key>
<column name="parentId" />
</key>
<one-to-many class="childClass" />
</set>
</class>
When try to update the parent, I always get LazyInitializationException.
I need to keep a audit log of any changes make to parent's properties (excluding children property). I don't want to make the lazy="false" due to performance issue.
If use saveOrUpdate() or update() instead of saveOrUpdateCopy(object), i will not get the snapshot of previousState of parent class.
I try locked(object, LockMode.None) before calling saveOrUpdateCopy(object), but changes are not save to db.
For temparaly measure, I now used update(object). Inside the inerceptor.onFlushDirty(..) method, I add following code to get the previousState:
Code:
if (previousState == null)
{
Object original = session.get(entity.getClass(), session.getIdentifier(entity));
previousState = persister.getPropertyValues(original);
}
Any idea?
Code: