Esempio n. 1
0
  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;
  }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }