开发环境: Struts 1.2 + Spring 1.2.8 + Hibernate 3.2遇到的问题: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来解决。
生存或毁灭,这是个必答之问题:是否应默默的忍受坎苛命运之无情打击,还是应与深如大海之无涯苦难奋然为敌,并将其克服。此二抉择,究竟是哪个较崇高?