I want to update my Hibernate 2.1 lib to Hibernate3 lib. And I have met a confusing
problem.
When I operate on a detached object , I often met an exception of
ERROR org.hibernate.LazyInitializationException:(LazyInitializationException.java:19)
- could not initialize proxy - the owning Session was closed
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:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at com.hs.battlegame.domain.Player$$EnhancerByCGLIB$$98e3ec06.toString(<generated>)
From the stack trace, you know I have a POJO naming of com.hs.battlegame.Player, and now it has been detached
from hibernate session. When I make a log using something like player.toString(), it will produce the
stack trace above.
I found it is because of the attribute "target" of AbstractLazyInitialzer is null and should be
initialized, but it is a detached object and the session has been closed. I wonder why
the "target" attribute has not been initialized when the persistent object detached from hibernate
session?
I have enabled using query cache, and the first time the Player object loaded from database,
it is always a normal object of Player, but when I refresh the IE browser and load the Player object from StandardQueryCache
with EHCache,I always get a Player$$EnhancerByCGLIB, and throw the exception above.
During my testing process , only few occasion the "target" attribute is not null.
I have changed the Hibernate3 package reference of my dao code and the XML DOCTYPE of my hibernate mapping files.
Do I need to make any more changes in my hibernate mapping file or java code?
|