-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Could i pass objects between sessions using session.get() ?
PostPosted: Mon Jan 10, 2005 3:24 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.