could not initialize proxy - the owning Session wa HibernateJavaApacheSpringSUN
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session 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$$e10be950.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)
分析原因:
由于Spring控制的Hibernate的生命周期只针对数据层和服务层,而未管理到表现层,所以会出现the owning Session was closed的现象。针对这一点,我通过hibernate filter的方式来解决。
解决方法:
在web.xml中配置filter来解决。
<!-- 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 </ filter-name > < url-pattern > *.do </ url-pattern > </ filter-mapping >
推荐阅读
-
could not initialize proxy - no Session
-
解决:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
HTTP Status 500 - Could not write content: could not initialize proxy - no Session
-
could not initialize proxy - no Session:解决懒加载(排除不需要查询显示的属性)
-
org.hibernate.LazyInitializationException: could not initialize proxy [xxxx] - no Session异常
-
Hiberante异常之org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
【记录】异常:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
Jpa项目报错:org.hibernate.lazyinitializationexception could not initialize proxy - no session
-
org.hibernate.LazyInitializationException: could not initialize proxy no Session
-
jpa 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session