-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy initialization exception occurs when lazy is set
PostPosted: Wed Mar 08, 2006 2:53 am 
Newbie

Joined: Tue Mar 07, 2006 3:20 am
Posts: 4
Location: Pune
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:hibernate3

Mapping documents:

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

Full stack trace of any exception that occurs:
HTTP Status 500 -

type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: failed to lazily initialize a collection of role: src.model.Forums.discussList - no session or session was closed
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
src.control.DiscussForum.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
root cause
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: src.model.Forums.discussList - no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
org.apache.jsp.pages.forum.discuss_jsp._jspService(discuss_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
src.control.DiscussForum.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.

Apache Tomcat/5.0.27


Name and version of the database you are using:MySQL v4.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


My project works fine when the lazy is set to false but gives trouble when lazy is set to true. I am using the appfuse architecture with spring and hibernate. My database is MYSQL v5.0 and am using Apache Tomcat Server.
Please help


regards
Chanchal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 3:28 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
you have to initialize the collection before sending data to presentation/busines tier . accessing collections/accociations outside a session with out explicit initialization throws the LazyInitializationException

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 3:34 am 
Newbie

Joined: Tue Mar 07, 2006 3:20 am
Posts: 4
Location: Pune
zzyborg wrote:
you have to initialize the collection before sending data to presentation/busines tier . accessing collections/accociations outside a session with out explicit initialization throws the LazyInitializationException


Do you mean we should manually initiallize the set. then where is the ORM being performed my appfuse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 3:40 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
it is ORM , lazy initialization works fine only inside a session . its still a question mark on how to do it efficiently . as far as i came across , one way is to initialize the collections when u are using lazy=true, or use a query with eager fetch on the particular collection . i think DTOs may be of help too, but in that case , still you have to do the things above

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 6:35 am 
Newbie

Joined: Tue Mar 07, 2006 3:20 am
Posts: 4
Location: Pune
zzyborg wrote:
it is ORM , lazy initialization works fine only inside a session . its still a question mark on how to do it efficiently . as far as i came across , one way is to initialize the collections when u are using lazy=true, or use a query with eager fetch on the particular collection . i think DTOs may be of help too, but in that case , still you have to do the things above


Thankyou very much For your help.....
I get some idea about it now. Can you please give me some sample code if it is not too much trouble.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 7:05 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
check out this link
http://www.hibernate.org/43.html

i may appreciate your rating if this proves helpful :)

_________________
sHeRiN
thanks for your ratings ...... :)


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