Same question here. All my investigations turned out that modifying that all modifications to the object are not persisted in the database.
I tried out for example an PreUpdateEventListener. The listeners method "onPreUpdate" is called, but any changes to the objects are ignored.
My listener looks like this:
Code:
[...]
public class MyListener implements PreUpdateEventListener {
@Override
public boolean onPreUpdate(PreUpdateEvent event) {
System.out.println("Listener was called!");
if (event.getEntity() instanceof MyObject) {
((MyObject)event.getEntity()).setAttribute("new value");
}
return false;
}
}
Generally, hibernate's complete event listener system seems to be very rarely documented. Or do I miss something? For example finding out that the return value of the onPreUpdate says whether or not to veto the operation needs some research.
Since the method is call PRE-update it's *very confusing*, that the changes are ignored. Moreover: JPA's counterpart @PreUpdate works as expected: All changes to the object are persisted in the database.
Same/similar problem is described here:
viewtopic.php?t=953934IMHO, the only way to change the entitie's state before persisting in pure hibernate (without JPA container) is to use hibernate's interceptors and use the Object[] state and String[] propertyNames values passed to onSave(..) or onFlushDirty(..) which is some kind of cumbersome ...
Any comments?