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?