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.jarThe 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.
Code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "filter", fetch = FetchType.EAGER)
private List<OrderFilterColumn> filterColumns;
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.