This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Groovy and the fly likes failed to lazily initialize a collection of role Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "failed to lazily initialize a collection of role" Watch "failed to lazily initialize a collection of role" New topic
Author

failed to lazily initialize a collection of role

Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
Hi everyone,

I execute a query in my controller, then I pass the results (I checked, they're correct) by chaining it to another page. Anyway I've the following message :
Error 500:
Servlet: default
URI: /package/recherche/list
Exception Message: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
Caused by: Error processing GroovyPageView: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
Class: /WEB-INF/grails-app/views/recherche/list.gsp
At Line: [-1]


With the stack :
2011-09-23 11:37:17,977 [http-9090-2] ERROR view.GroovyPageView - Error processing GroovyPageView: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2_closure35.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp:89)
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp:76)
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp)
at home_user_Projets_package_grails_app_views_recherche_list_gsp.run(home_user_Projets_package_grails_app_views_recherche_list_gsp:104)
at java.lang.Thread.run(Thread.java:679)
2011-09-23 11:37:18,051 [http-9090-2] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /package/recherche/list
Stacktrace follows:
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
at java.lang.Thread.run(Thread.java:679)
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: package.Profil.competences, no session or session was closed
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2_closure35.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp:89)
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp:76)
at home_user_Projets_package_grails_app_views_recherche_list_gsp$_run_closure2.doCall(home_user_Projets_package_grails_app_views_recherche_list_gsp)
at home_user_Projets_package_grails_app_views_recherche_list_gsp.run(home_user_Projets_package_grails_app_views_recherche_list_gsp:104)


I thought it was because of a lazy loading, Grails doco says that "In GORM, one-to-one and many-to-one associations are by default non-lazy". I've looked at the side of scopes, but I found nothing. Anyway, I've tried to code explicit eager behavior, still no success.

One word about my query : I recover datas from a many to many relationship, but I created the intermediate table (Competence) because I wanted to add informations.

Here is the code :







And ProfilController, which receives the parameters (only the usefull part)
Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
I pseudo-resolved this via a hack. Instead of sending the results to the closure of the controller corresponding to the page, I've modified the receiver controller to do the treatment then passing the results to the page.

But I still don't know why the results disappear when I pass the list to another url. I'm really interested in this. If someone has the answer...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: failed to lazily initialize a collection of role
 
Similar Threads
Acess list elements on foreach JSTL tag
failed to lazily initialize
how to "reattach" a serialized entity to a hibernate sesison?
EJB Lazy Loading etc..
What are the FetchType Lazy and Eager?