首页 > Web开发 > 详细

解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒载入问题

时间:2016-01-03 20:56:14      阅读:474      评论:0      收藏:0      [点我收藏+]

问题描写叙述:

Struts Problem Report

Struts has detected an unhandled exception:

Messages:
  1. could not initialize proxy - no Session
  2. Error reading ‘name‘ on type future.oa.domain.Department_$$_jvstb8a_0
  3. 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.

解决方法:
解决懒载入问题。

方法一:(直接将懒载入关闭):
在 .hbm.xml 里
<!--  lazy="false"关闭懒载入 -->
<set name="children" cascade="delete" lazy="false">   
<key column="parentId"></key>
<one-to-many class="Department"/>
</set>
缺点:一些懒载入的长处也用不了了。

方法二:
在 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里 再打开懒载入。

解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒载入问题

原文:http://www.cnblogs.com/lcchuguo/p/5097048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!