Closed spring-projects-issues closed 19 years ago
Juergen Hoeller commented
Looks like you got caught by Hibernate3's changed default for lazy loading: all references are lazy by default in Hibernate3. If you want to have Hibernate2-style default behavior, you need to set the "default-lazy" flag to "false" in your mapping files:
\
Gopal Koratana commented
OOPS. Resolved the LazyInitializationException problem by specifying lazy="false" on the class declaration since in hibernate3 it defaults to true.
And I was using xdoclet to generate the mapping so did not even realize that.
Thanks Gopal
Gopal Koratana commented
Thanks for the quick response Juergen. I guess many people will overlook this detail. Hope this post helps them save time.
Gopal
Juergen Hoeller commented
OK, so it's here to be found by others, but it's not actually a Spring issue :-)
Juergen
Swathi T commented
Hi
I just inherited a Spring-Xdoclet-Hibernate project. Have never used Hibernate before. One of the first requirements was to upgrade to Hibernate 3. The upgrade seems to have gone well until I got the error below.
The xdoclet entry in my class is
/**
* @hibernate.many-to-one
* cascade="none"
* class="xxxx.xxx.xxxx.xx.xxxx"
*/
What do I need to change to get this to work without going bach to a hibernate2 style behavior.
08:21:04,027 INFO SimpleObjectListController:138 - Returning view...
08:21:05,579 ERROR LazyInitializationException: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:133)
at com.deploy.requesttracker.model.hibernate.CustomerBeanHibernateImpl$$EnhancerByCGLIB$$d103daf8.getName(\
Juergen Hoeller commented
Quoting myself from above:
Looks like you got caught by Hibernate3's changed default for lazy loading: all references are lazy by default in Hibernate3. If you want to have Hibernate2-style default behavior, you need to set the "default-lazy" flag to "false" in your mapping files:
\
Swathi T commented
Juergen, Thank you very much for your prompt reply. I did read your comment. Since I use xdoclet, I have no control on the mapping files directly. I had modified my xdoclet entry to
/**
@hibernate
.many-to-oneBut still got the same error. It looks like I am missing on some fundamentals here. Could you please suggest some Hibernate material that I could read..
-s
Juergen Hoeller commented
Well, the problem is that Hibernate3 loads *each and every association" lazy by default now. So you would have to put lazy=false marks on all associations: not just on one-to-many and many-to-many (i.e. collections), but on many-to-one and one-to-one references too.
I guess the only way out of this is finding out how to specify default-lazy="false" with XDoclet (I'm not an expert there myself), or abandon XDoclet completely and resort to writing the XML mapping files yourself (with maybe the initial version generated by XDoclet).
Juergen
Gopal Koratana commented
For an quick and dirty fix (Till Xdoclet fixes this problem), that will still allow you to use your x-tags without change is to do this
change the following
<hibernate-mapping
Gopal Koratana opened SPR-900 and commented
I was using Spring 1.0 with Hibernate2 for my DAO layer. Xdoclet is used to generate hibernate mapping.
Spring among other thing is also used to manage transaction (declarative). This is working perfectly.
I decided to upgrade to Hiebernate3 and hence Spring 1.2 RC2. Had to upgrade couple of hibernate and spring jar's. Figured out some of the methods in hibernate temple are gone but overall the migration was seamless. The systems build and deployes.
BUT When I deploy the webapp (in Tomcat 5.0 and JDK 1.4.2), and make a DAO call and get the entity and try to access some property within the entity I am getting this exception
Any Suggestions. Looks like I am missing some kind of configuration.
Thanks Gopal
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.manheim.dms.entity.security.vo.Role$$EnhancerByCGLIB$$4ad14d28.getActive(\)
at com.manheim.dms.system.SecurityManager.buildProfile(SecurityManager.java:85)
at com.manheim.dms.handler.AdminHandler.authenticate(AdminHandler.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.cysive.framework.servlet.controller.ProxyRequestHandler.processRequest(ProxyRequestHandler.java:104)
at com.cysive.framework.servlet.controller.Dispatcher.processAction(Dispatcher.java:1040)
at com.cysive.framework.servlet.controller.Dispatcher.processRequest(Dispatcher.java:1081)
at com.cysive.framework.servlet.controller.Dispatcher.doPost(Dispatcher.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
Affects: 1.2 RC2