Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi
Hibernate version: 3.05
i've just started to use the event listener classes in hibernate3 and am a little confused as to their intended use.
what i am trying to achieve is to trigger an additional update to the one being performed by the system. basically - if record type x is being updated, update record y also. i have tried using preinsert, preupdate and onflushentity events but the second update is not happening. i have added debug statements that show me that the listeners are being triggered after a commit is called and before the commit returns.
some sample code:
Code:
public void onFlushEntity(FlushEntityEvent event) {
Object entity = event.getEntity();
Log.debug("Listener: onFlushEntity for entity " +
entity.getClass().getName());
Session session = event.getSession();
if (entity.getClass() == MyObject.class) {
MyObject myObject = (MyObject)entity;
Integer secondObjectId = myObject.getSecondObject().getObjectId();
SecondObject secondObject = (SecondObject)session.load(SecondObject.class, secondObjectId);
secondObject.setSomeBooleanValue(new Boolean(false));
session.update(secondObject);
}
i have tried session.flush() both here and in the underlying tx mechanism that handles the tx control and closes the session at the end. no change.
when session.flush() is called i can see that the listeners are triggered again and so forth but the second object's record is not being updated.
do i have it all wrong - is there no intention to use the event listeners for further entity changes to be persisted?
any suggestions would be appreciated.
Takis