public long createAndStorePerson(String name, int age) { Session session = sessionFactory.getCurrentSession(); Long personId; Person person = new Person(); person.setAge(age); person.setFirstname(name); person.setLastname("abc"); personId = (Long) session.save(person); return personId; }
public void addEmailToPerson(Long personId, String emailAddress) { Session session = sessionFactory.getCurrentSession(); Person aPerson = (Person) session.load(Person.class, personId); // adding to the emailAddress collection might trigger a lazy load of the collection aPerson.getEmailAddresses().add(emailAddress); }
public void addPersonToEvent(Long personId, Long eventId) { Session session = sessionFactory.getCurrentSession(); Person aPerson = (Person) session.load(Person.class, personId); Event anEvent = (Event) session.load(Event.class, eventId); aPerson.getEvents().add(anEvent); }