Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LazyInitializationException illegal access to loading collection

 
lastranchie tiwari
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.
 
Darko Ristic
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic