I am getting the following exception working with hibernate:
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134) at com.benefitpoint.cmp.security.Permission$$EnhancerByCGLIB$$15036d4c.hashCode(<generated>) at java.util.HashMap.hash(HashMap.java:261) at java.util.HashMap.containsKey(HashMap.java:339) at java.util.HashSet.contains(HashSet.java:180)
This doesn’t happen every time I access this particular page. I have narrowed it down to the following scenario:
• Request A retrieves objects from hibernate. The objects include lazy loaded collections and object graphs which are not full navigated and therefore only partially realized. • Request A results in those same objects being stored in the L2 cache (ehcache) • Request B retrieves objects from hibernate. The objects retrieved include some of the same objects stored in L2 cache from request A. • When request B navigates to those objects which are not realized from the previous process, the exception above is thrown.
As I debug, it looks like the proxied set in these not realized objects has a reference to a session which is closed. I set debug points on the session impl and did not see a preceeding close in the request. It seems to me that this session reference is a stale reference from Request A (?). To complicate matters, the application makes use of hibernate is some non-standard ways. Request A does not use the OpenSessionInViewFilter, Request B does. Request A uses more manual hibernate processing whereas Request B uses a more standard spring stack.
My questions:
• Does hibernate support storing non-realized lazy objects in the L2 cache for future use by a different session? • Is this likely an issue with a mis-configuration of hibernate in the application?
My environment:
Hibernate 3.0.5 Spring 1.2.7 JDK 1.4.2 Ehcache 1.1
Thanks in advance.
Ben
|