Hibernate not obedient--could not initialize proxy-the owning sessions was closed
Development Environment:
Struts 1.2 + Spring 1.2.8 + Hibernate 3.2
the problems encountered:
Org.hibernate.LazyInitializationException:could not initialize Proxy-the owning sessions was closed
At Org.hibernate.proxy.AbstractLazyInitializer.initialize (abstractlazyinitializer.java:60)
At Org.hibernate.proxy.AbstractLazyInitializer.getImplementation (abstractlazyinitializer.java:111)
At Org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke (cgliblazyinitializer.java:172)
At com.zhjy.gea.module.affair.domain.affair$ $EnhancerByCGLIB $ $e 10be950.getaffaircatalogs (<generated>)
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:585)
At Org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod (propertyutilsbean.java:2049)
At Org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty (propertyutilsbean.java:1286)
At Org.apache.commons.beanutils.BeanUtilsBean.copyProperties (beanutilsbean.java:284)
At Org.apache.commons.beanutils.BeanUtils.copyProperties (beanutils.java:137)
Analysis Reason:
The owning session is closed occurs because the hibernate lifecycle of Spring control is not managed at the layer of data and services, but not the presentation layer. In response to this, I hibernate filter the way to solve.
Workaround:
Configure filter in Web.xml to resolve. <!-- hibernate session filter -->
< filter >
< Filter-name > Hibernatefilter </filter-name >
< filter-class > Org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class >
</filter >
< filter-mapping >
< filter-name > Hibernatefilter </fi Lter-name >
< url-pattern > *.do </url-pattern >
</filter-mapping >
Remember here, hope to encounter the same problem friends, less detours. :)