zoukankan      html  css  js  c++  java
  • 懒加载异常LazyInitializationException:19

    16:09:57,453 ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed
    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.zw.domain.Account$$EnhancerByCGLIB$$b9abda1e.getName(<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:597)
    at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:851)
    at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1414)
    at ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:60)
    at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:147)
    at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.getProperty(ObjectAccessor.java:17)
    at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2210)
    at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.ASTChain.getValueBody(ASTChain.java:141)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.Ognl.getValue(Ognl.java:494)
    at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:206)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:276)
    at org.apache.struts2.components.Property.start(Property.java:141)
    at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
    at org.apache.jsp.find_jsp._jspx_meth_s_005fproperty_005f8(find_jsp.java:532)
    at org.apache.jsp.find_jsp._jspx_meth_s_005fiterator_005f0(find_jsp.java:324)
    at org.apache.jsp.find_jsp._jspService(find_jsp.java:205)

    这是一个lazy使用后的Exception,使用迟时加载,在session(hibernate里的session),关闭后使用该对象的未加载变量,也就是说session已经关闭,没有保存到内存中,然后你使用了,导致该异常。在<many-to-one>中这错误很常见,字面意义就是不能被初始化,因为session已经关闭了。

    解决方法:将多对一中的一那边xxx.hbm.xml中懒加载关掉 (多个学生对应一个管理者)

    管理者:

    <class name="Account" table="account"  lazy="false">
    <id name="id" >
    <generator class="native"/>
    </id>
    <property name="name"/>
    <property name="passwd"/>
    <set name="student">
    <key column="accountid"></key>
    <one-to-many class="Student"/>
    </set>

    </class>

    学生:

    <class name="Student" table="student" >
    <id name="id" >
    <generator class="native"/>
    </id>
    <property name="name"/>
    <property name="sex"/>
    <property name="age"/>
    <property name="xh"/>
    <property name="birthday"/>
    <property name="sal"/>
    <many-to-one name="account" column="accountid" />

    </class>

    以上仅是个人观点,希望可以对您有帮助,欢迎拍砖(*^_^*)/

  • 相关阅读:
    分享一个自己写的vue多语言插件smart-vue-i18n
    利用vw+rem实现移动web适配布局
    你说前端不了解业务?
    小程序开发总结一:mpvue框架及与小程序原生的混搭开发
    小码农的职场人生一:由张小平离职引发的一些吐槽
    javascript本地缓存方案-- 存储对象和设置过期时间
    手淘移动适配方案flexible.js兼容bug处理
    微信小程序入坑之自定义组件
    vuejs开发组件分享之H5图片上传、压缩及拍照旋转的问题处理
    非域环境下使用证书部署数据库(SqlServer2008R2)镜像
  • 原文地址:https://www.cnblogs.com/alvin-perfect/p/4402740.html
Copyright © 2011-2022 走看看