-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem with lazing initialization.
PostPosted: Sun Oct 02, 2005 10:38 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Hi I'm getting the following error: could not initialize proxy - the owning Session was closed. Funny thing is i'm getting partially my data.

Hibernate version: 3.0.5

Mapping documents:

<class name="org.mamoth.Genre" table="genres">

<cache usage="nonstrict-read-write"/>

<id name="genreID" column="GenreID" type="int" unsaved-value="0">
<generator class="assigned" />
</id>
<property name="genre" type="java.lang.String">
<column name="Genre" sql-type="varchar" length = "25" not-null="true"/>
</property>
<property name="description" type="java.lang.String">
<column name="Description" sql-type="varchar" length="100" not-null="false"/>
</property>
</class>


Code between sessionFactory.openSession() and session.close():

hSession.createCriteria(Genre.class).list();


Full stack trace of any exception that occurs:
2005-10-02 22:56:12,953 ERROR [org.hibernate.LazyInitializationException] could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at org.mamoth.Genre$$EnhancerByCGLIB$$61dcfc7b.getGenre(<generated>)
at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:259)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
2005-10-02 22:56:12,953 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/mamoth].[jsp]] Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at org.mamoth.Genre$$EnhancerByCGLIB$$61dcfc7b.getGenre(<generated>)
at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:259)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
2005-10-02 22:56:39,828 DEBUG [org.hibernate.jdbc.ConnectionManager] running Session.finalize()
2005-10-02 22:57:10,343 DEBUG [org.hibernate.jdbc.ConnectionManager] running Session.finalize()



Name and version of the database you are using: MySQL

The generated SQL (show_sql=true): false

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 11:00 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
this one comes up often and the only thing you can do is retrace your steps. you'll find that you just overlooked something simple.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:31 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
Did you have you Session opened in Servlet ? Maybe you should use 'openSessionInView' pattern to make it possible to navigate lazy-loaded hibernate objects


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 11:58 am 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
hibernate load objects lazily. so your object will be loaded when you try to first access it and the session which actually executed this query needs to be open .

In this case, it seems that you are trying to access the object in a jsp.
What you can do is use a filter to open and close session. In this way your session will be open for your jsps also


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 12:38 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Humm this is what I'm doing exactly... Maybe not the best way but what ever... lol Also to let you know this worked perfect . 2.1.7 but now I'm migrating to 3.0.5


Somewhere in my jsp...

<some html>
<%

GenreDAOImpl genreDAO = new MyDAOImpl();

genreDAO.getGenreList();

%>
</some html>


Within the getGenreList() I get my session

So you saying I should do this on the filter level right? This is also better for me to clean up my DAO


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 12:41 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Well to be honest, code like that in JSP makes baby Jesus cry.

Please consider something not quite as evil as dumping your DAO in JSP. There are so many alternatives, Webwork, Seam even Struts is better than doing that.

It leads to incredibly difficult to maintain pages and you'll never be able to let the average web monkey near them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 12:41 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
infectedrhythms wrote:
Humm this is what I'm doing exactly... Maybe not the best way but what ever... lol Also to let you know this worked perfect . 2.1.7 but now I'm migrating to 3.0.5


Somewhere in my jsp...

<some html>
<%

GenreDAOImpl genreDAO = new MyDAOImpl();

genreDAO.getGenreList();

%>
</some html>


Within the getGenreList() I get my session

So you saying I should do this on the filter level right? This is also better for me to clean up my DAO


where is the session opened and closed ?
are you using the threadlocal pattern ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 12:43 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
in hibernate 3.0 all mappings assume to have lazy="true" by default, so you need to specify lazy"false" excplisitly everywhere were you have no such attribute (as in hibernate 2.x it was defaulted to 'lazy=true')

How does you DAO controll the Session on the page ?


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