Sorry by my english , it´s my first post ,but the question is
How could i pass objects between sessions ?
one many many one
People ---- PeopleDestiny ---- Destiny
Method 1 -> example
SessionFactoryDAO sfd = SessionFactoryDAO.getInstance();
SessionFactory sf = sfd.getSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
People peopleTemp = (People) s.get(People.class, new Long(3));
Destiny destinyTemp = (Destiny) s.get(Destiny.class, new Long(3));
tx.commit();
s.close();
PeopleDestinyDAO pd = new PeopleDestinyDAO();
pdd.insertPeopleDestiny(destinyTemp,peopleTemp);
Method 2
public boolean insertPeopleDestiny(Destiny destiny, People people)
throws HibernateException {
Session s1 = sf.openSession();
List result = null;
Transaction tx = null;
try {
tx = s1.beginTransaction();
if (pessoa.getId() == null) {
s1.save(people);
}
if (destino.getId() == null) {
s1.save(destiny);
}
PeopleDestiny pd = new PeopleDestiny(destiny, people);
s1.save(pd);
tx.commit();
return true; ......
ERROR
When i close the session before i call insertPeopleDestiny();
Failed to lazily initialize a collection - no session or session was closed
|