-->
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.  [ 2 posts ] 
Author Message
 Post subject: Could not initialize proxy - the owning Session was closed
PostPosted: Fri May 13, 2005 1:18 pm 
Newbie

Joined: Tue May 10, 2005 11:53 am
Posts: 4
WTH?

This works:

Wwritten directly in a .jsp just for edicational purposes and ease of implementation...

<%
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
%>

<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>

Name: <%= dog.getName() %> - <%= dog.getSex() %><BR>

<%
}
tx.commit();
HibernateUtil.closeSession();
%>

This does not and produces the error in the subject.

<%
ArrayList dogList = new ArrayList();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
dogList.add( dog );
}
tx.commit();
HibernateUtil.closeSession();
%>


<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>


Top
 Profile  
 
 Post subject: Re: Could not initialize proxy - the owning Session was clos
PostPosted: Fri May 13, 2005 2:05 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
JeanNiBee wrote:
WTH?

This works:

Wwritten directly in a .jsp just for edicational purposes and ease of implementation...

<%
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
%>

<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>

Name: <%= dog.getName() %> - <%= dog.getSex() %><BR>

<%
}
tx.commit();
HibernateUtil.closeSession();
%>

This does not and produces the error in the subject.

<%
ArrayList dogList = new ArrayList();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
dogList.add( dog );
}
tx.commit();
HibernateUtil.closeSession();
%>


<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>


What version of hibernate are you using ?
What do your mapping files look like ?
Exactly what exception are you receiving ? (Include the stack trace)

If you're using Hibernate 3.0.x, read the documentation. It covers this situation very explicitly when talking about Lazy Initialization.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.