This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

LazyInitializationException illegal access to loading collection

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am getting a LazyInitializationException in my application. The nature of this exception is irregular. It does not have a fixed pattern or predefined steps to reproduce.

The trace of exception is -

[com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor] illegal access to loading collection
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:363)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentBag.toArray(PersistentBag.java:280)
at java.util.Collections.sort(Collections.java:116)
..........

In my project we use hibernate-core 3.3.0.SP1.jar and Spring 2.5.6.SEC01.jar

The exception talks about Lazy initialization, but the Object on which i am getting this exception has only one collection associated with it, which is Eagerly fetched.


An object "OrderFilter" has multiple "OrderFilterColumn" associated with it. What i do is searching/saving/deleting these OrderFilter's.

Another similar exception that i am getting is -

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: domain.OrderFilter.filterColumns, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentBag.toArray(PersistentBag.java:280)
at java.util.Collections.sort(Collections.java:116)
.............

I cant find out the root cause to these exceptions.

Any help would be greatly appreciated.

Thanks.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How You manipulate with results after executing Query/Criteria object?
Listing list(), iterating iterate(), using scrollable resultset or ?
 
lastranchie tiwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I iterate over filter columns in the manner

and i get exception while getting the filter columns i.e. orderFilter.getFilterColumns()

implementation of orderFilter.getFilterColumns() is -

Exception occurs on line -
Collections.sort(filterColumns);
It says : failed to lazily initialize a collection of role: .domain.OrderFilter.filterColumns, no session or session was closed

Thanks
 
Darko Ristic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about Query/Criteria object, can You post that code?
 
lastranchie tiwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please tell which query are you talking about?
Is it the one that retrieves the object OrderFilter or the one that retrieves the filter columns(List <OrderFilterColumn>) for OrderFilter.

My BO for OrderFilter looks like -


I retreive list of filter columns using the getter method (orderFilter.getFilterColumns()).

OrderFilter is retreived using EntityManager's find method - find(Class<T> entityClass, Object primaryKey).

Thnks.

 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic