解决org.hibernate.LazyInitializationException: could not initialize proxy - no Ses
来源:程序员人生 发布时间:2014-11-11 08:57:20 阅读次数:5842次
问题描写:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: |
- could not initialize proxy - no Session
- Error reading 'name' on type future.oa.domain.Department_$$_jvstb8a_0
- javax.el.ELException: Error reading 'name' on type future.oa.domain.Department_$$_jvstb8a_0
|
File: |
org/hibernate/proxy/AbstractLazyInitializer.java |
Stacktraces
org.apache.jasper.JasperException: javax.el.ELException: Error reading 'name' on type future.oa.domain.Department_$$_jvstb8a_0
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
.......
javax.el.ELException: Error reading 'name' on type future.oa.domain.Department_$$_jvstb8a_0
javax.el.BeanELResolver.getValue(BeanELResolver.java:110)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:183)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
......
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:164)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:285)
org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
future.oa.domain.Department_$$_jvstb8a_0.getName(Department_$$_jvstb8a_0.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties
file.
解决方法:
解决懒加载问题。
方法1:(直接将懒加载关闭):
在 .hbm.xml 里
<!-- lazy="false"关闭懒加载 -->
<set name="children" cascade="delete"
lazy="false">
<key column="parentId"></key>
<one-to-many class="Department"/>
</set>
缺点:1些懒加载的优点也用不了了。
方法2:
在 web.xml里(注:要在 <!-- 配置struts2核心的过滤器 --> 之前)
<!-- 配置Spring的用于解决懒加载问题的过滤器 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
然后在 *.hbm.xml里 再打开懒加载。
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠