-->
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.  [ 2 posts ] 
Author Message
 Post subject: Auto loading of referenced objects
PostPosted: Mon Mar 17, 2008 8:07 pm 
Regular
Regular

Joined: Mon Mar 10, 2008 6:40 pm
Posts: 114
Still learning hibernate, can someone recommend the best way to implement the following?

Here's some pseudo code for my issue:
Code:
Person person1 = new Person("John");
Person person2 = new Person("David");
Event party = new Event("Adam's house");
person1.addParty(party);
person2.addParty(party);
long id1 = personDao.addPerson(person1);
long id2 = personDao.addPerson(person2);


Elsewhere in the code:
Code:
Person person1 = personDao.get(id1);
Set<Person> participants = person1.getParties()[0].getParticipants();
assertEquals("Should see the party event", 1, person1.getParties().size());
assertEquals("Only 1 other person was at the only party", 2, participants.size());


the last assertion above fails, the person object sees the party event objects (in this case only 1) properly. But it does not then follow up and get the Person objects referenced by that party event. How can I make that last assertion pass? Should I call eventDao.get(id) (equivalent to session.load(Event.class, id)) on each event in Person? What's the best way to make this happen?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 4:55 pm 
Regular
Regular

Joined: Mon Mar 10, 2008 6:40 pm
Posts: 114
Sorry guys, this was due to a bug in my equivalent getParties() method. All works as expected now.


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

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.