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.  [ 7 posts ] 
Author Message
 Post subject: could not initialize proxy - the owning Session was closed
PostPosted: Fri Oct 28, 2005 10:22 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
hello,

I got the following error in my jsp page :
Error 500 : could not initialize proxy - the owning Session was closed

My jsp page fetch a vector of objects loaded with hibernate in a struts action.

I noticed that if I do not call session.close() after having constructed my vector, I do not have the error in my jsp.

But if call session.close(), i got this error...

does someone can help please?

Thanks

Here is the code of my struts action



Vector personsVector = new Vector();

Context ctx = new InitialContext();
SessionFactory sf = (SessionFactory) ctx.lookup("HibernateSessionFactory");
Session hibSession = sf.openSession();

Query query = hibSession.createQuery("from Person person where person.comp_id.specialid1=? order by person.comp_id.specialid2 desc");
query.setInteger(0,Integer.parseInt(1354852));
//String.valueOf();
Iterator it = query.iterate();

while(it.hasNext()) {
Person person = (Person) it.next();
personsVector.addElement(person);
}

request.setAttribute("personsVector",personsVector);

hibSession.flush();
hibSession.close();//cause the error 500!!


Top
 Profile  
 
 Post subject: lazy
PostPosted: Fri Oct 28, 2005 10:46 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
You have some properties mapped as lazy ( lazy="true" ) and therefore as you trying to get their values after session closure, H throws that exception.

set lazy="false" or use Open-session-in view strategy:
http://www.hibernate.org/43.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 11:05 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
According to the post below, this seems to doesn't work:

http://forum.hibernate.org/viewtopic.php?t=949399

Thanks anyway


Top
 Profile  
 
 Post subject: does work
PostPosted: Fri Oct 28, 2005 11:35 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It does work in my experience, It looks like that guy did not have time to implement the proper solution (....I have 12 hours till...).

Note, lazy="false" should be set not only on properties of the object you are loading but on properties of properties if you need them. It is sometimes hard to track, for example:
if you need to show user.department.boss.name
then not just boss property of department should have specified lazy='false'

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 11:50 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I've found that having the wrong versions of the extra jar files that hibernate3 depends on also makes this error appear

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: Re: does work
PostPosted: Fri Oct 28, 2005 11:59 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
kgignatyev wrote:
It does work in my experience, It looks like that guy did not have time to implement the proper solution (....I have 12 hours till...).

Note, lazy="false" should be set not only on properties of the object you are loading but on properties of properties if you need them. It is sometimes hard to track, for example:
if you need to show user.department.boss.name
then not just boss property of department should have specified lazy='false'


Thanks but when reading "Open Session in View", the "proper solution" as you said doen't seem so obvious...it seems that none of solutions is proper and some are really difficult to develop and we can't be sure to have something working after hours of coding :o)

thanks anyway..looking on other solution than hibernate for now...(EJB3 sounds better)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 12:00 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
kochcp wrote:
I've found that having the wrong versions of the extra jar files that hibernate3 depends on also makes this error appear


If you read the article above on "Open Session in View" you will see that it's not just a problem of JAR versions :o)

Thanks anyway for your post


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

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.