-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: saveOrUpdate event lister not working?
PostPosted: Tue Apr 18, 2006 2:49 pm 
Newbie

Joined: Thu Apr 13, 2006 8:00 pm
Posts: 2
I've got this code

Listener Class
****************************************
public class HibernateEventListener implements SaveOrUpdateEventListener {

private static final long serialVersionUID = 8991739587379538184L;

/**
* When a {@link VersionedObject} or a {@link Version} is updated, update
* its old versions so they get their end times set appropriately.
*/
public void onSaveOrUpdate(SaveOrUpdateEvent event) {
Object obj = event.getObject();

System.out.println("in listener" + obj.getClass());
if (obj instanceof VersionedObject<?, ?>) {
((VersionedObject<?, ?>) obj).updateOldVersions(event.getSession());
} else if (obj instanceof Version<?>) {
((Version<?>) obj).getContinuity().updateOldVersions(event.getSession());
}
}

}
********************************************
Configuration
********************************************

AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.getEventListeners().setSaveOrUpdateEventListeners(
new SaveOrUpdateEventListener[] {new HibernateEventListener(),
new DefaultSaveOrUpdateEventListener()});
return cfg;
*********************************************
My Test
*********************************************
public class TestUpdateCampaign extends CreateTestData {

public void setUp() throws Exception {
super.setUp();
//System.setProperty("com.adapt.clcm.storage.ignoreBuildProperties","true");
}

public void testUpdateCampaign(){
System.out.println("Test in a session");
Campaign myCampaign = csb.getCampaignById("402887740a8fac16010a8fad34b30007", 0);
myCampaign.setBudget(new Double("1002"));
session.update(myCampaign);
}

}
******************************************
Campaign is my object has getters and setters. We use versioned system that means a Campaign will have s set of CampaignVersions, whenever an update on a Campaign occurs, we create a new row of CampaignVersion and persist it into db. Now the problem is in my test when I call session.update(myCampaign), I never get the Campaign Object in my eventListener.

in my event listener I use this code

Object obj = event.getObject();

System.out.println("in listener" + obj.getClass());

However, I never get an object of Campaign. I got a whole list of Cascaded objects of CampaignVersion objects. It looks like it is not session.update(Campaign) that is triggering the event listener, but something else.

any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.