Ejemplo 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;
  }
Ejemplo 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);
 }
Ejemplo 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);
 }