Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes LazyInitializationException illegal access to loading collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "LazyInitializationException illegal access to loading collection" Watch "LazyInitializationException illegal access to loading collection" New topic
Author

LazyInitializationException illegal access to loading collection

lastranchie tiwari
Greenhorn

Joined: Nov 10, 2011
Posts: 5
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.
Darko Ristic
Greenhorn

Joined: Feb 23, 2012
Posts: 6
How You manipulate with results after executing Query/Criteria object?
Listing list(), iterating iterate(), using scrollable resultset or ?
lastranchie tiwari
Greenhorn

Joined: Nov 10, 2011
Posts: 5
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

Joined: Feb 23, 2012
Posts: 6
What about Query/Criteria object, can You post that code?
lastranchie tiwari
Greenhorn

Joined: Nov 10, 2011
Posts: 5

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LazyInitializationException illegal access to loading collection