`

org.hibernate.LazyInitializationException: could not initialize proxy - the owni

阅读更多
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

分析原因:
由于Spring控制的Hibernate的生命周期只针对数据层和服务层,而未管理到表现层,所以会出现the owning Session was closed的现象。针对这一点,我通过hibernate filter的方式来解决。

解决方法:

第一种:在web.xml中配置filter来解决。

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 <!--  hibernate session filter  --> 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 
 < filter > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草  
 < filter-name > hibernateFilter </ filter-name > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草  
 < filter-class >    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草  
 </ filter-class > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 
 </ filter > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 
< filter-mapping > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草  
 < filter-name > hibernateFilter </ filter-name > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草  
 < url-pattern > *.do </ url-pattern > 
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed - 天涯草 - 天涯草 
 </ filter-mapping >

第二种lazy="false"
也可以在Service 或者 dao 层把lazy的Hibernate.initialize强制加载它.
<many-to-one>里面的属性lazy="false"

<set>里面的属性lazy="true"
<one-to-many>
</set>
分享到:
评论

相关推荐

    集成spring的hibernate懒加载

    当你尝试在Controller层或者视图层访问懒加载的属性时,如果Session已经关闭("no Session..."错误),就会抛出`org.hibernate.LazyInitializationException`。这是因为懒加载的代理对象需要Session来执行数据库查询...

    poi4.1.2以及所有依赖,源码,文档.zip

    org.apache.poi:poi:4.1.2 org.apache.poi:poi-ooxml:4.1.2 org.apache.poi:poi-ooxml-schemas:4.1.2 org.apache.xmlbeans:xmlbeans:3.1.0 com.github.virtuald:curvesapi:1.06 com.zaxxer:SparseBitSet:1.2 commons...

    Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

    标题 "Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser" 提示了一个Java运行时错误,这通常意味着在尝试加载或初始化`JRStyledTextParser`类时遇到了问题。`JRStyledTextParser`是...

    HIbernate4.3.6整合c3p0所需jar

    Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.connection.C3P0ConnectionProvider] at org.hibernate.engine.jdbc.connections.internal....

    derby.jar 。。

    java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.AutoloadedDriver40 导致的原因: 在azkaban的server和executor中缺少一个叫derby.jar的包

    linux上实现视频截图

    if (formatContext.streams(i).codecpar().codec_type() == AVMediaType.AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; break; } } if (videoStreamIndex == -1) { System.err.println("未找到视频流"); ...

    Hibernate配置常见错误

    错误表现:在Session关闭后尝试访问懒加载属性,抛出“org.hibernate.LazyInitializationException: could not initialize proxy - no Session”异常。 解决方案:理解并合理使用Open Session in View(OSIV)模式...

    jasperreport maven打包后找不到字体解决方案

    jasperreport 用maven打包后找不到字体解决方案 net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font

    Hibernate映射导致的几个异常

    Could not initialize proxy - the owning Session was closed 这是Hibernate懒加载机制中的常见异常,当尝试访问一个已被关闭的Session中的懒加载属性时触发。例如,如果Session在使用`setFetchMode(FetchMode....

    Plsql 12连接Oracle时出现Could not initialize oci.dll解决方案 oracle 客户端

    在使用PL/SQL Developer 12连接Oracle数据库时,可能会遇到“Could not initialize oci.dll”这样的错误提示。这个错误通常表明系统无法找到或正确加载Oracle客户端的oci.dll库文件,这是Oracle Instant Client的一...

    基于SSH框架的BBS论坛JavaEE项目源码

    7.注册如果发送邮件激活的方式出错(返回页面错误org.hibernate.LazyInitializationException: could not initialize proxy - no Session) 8.禁止用户后不允许登录、发帖、回帖等 9.后台会员搜索中文名搜索乱码 ...

    hadoop1.0 Failed to set permissions of path 解决方案

    ERROR org.apache.hadoop.mapred.TaskTracker: Can not start task tracker because java.io.IOException: Failed to set permissions of path: \tmp\hadoop-admin \mapred\local\ttprivate to 0700 at org.apache...

    解决hbase client在windows环境下报NoClassDefFound问题

    解决hbase client在windows环境下报Could not initialize class org.fusesource.jansi.internal.Kernel32的问题,把jar包放入hbase client的lib包下,重新运行hbase.cmd shell即可

    instantclient_11_2.zip

    Could not initialize "D:\app\Happy\product\11.2.0\dbhome_1\bin\oci.dll" Make sure you have the 32 bits Oracle Client installed. OracleHomeKey: OracleHomeDir: D:\app\Happy\product\11.2.0\dbhome_1 ...

    derby_ui_plugin_1.1.1

    Derby UI Plugin 1.1.1 是一个专门为Java开发者设计的用户界面插件,它在Java学习过程中能提供极大的便利。这个插件版本号为1.1.1,暗示了它可能包含了一些修复和改进,以提升用户体验和兼容性。...

    Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常

    在这个特定的场景中,异常堆栈跟踪显示了 `Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer`,这表明系统无法找到 `org.apache.commons.collections.Transformer` 类。...

    Android代码-RetrofitUrlManager

    // When building OkHttpClient, the OkHttpClient.Builder() is passed to the with() method to initialize the configuration OkHttpClient = RetrofitUrlManager.getInstance().with(new OkHttpClient.Builder...

    UnlimitedJCEPolicyJDK8.rar

    java安装路径Java\jre\lib\security下替换这两个架包,即可解决 java.security.cert.CertificateException: Unable to initialize, java.io.IOException: Short read of DER length

    struts2驱动包

    信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_10\bin;C:\Program ...

    jacob_1.14.3.rar

    内涵jacob_1.14.3-x64.dll;jacob_1.14.3-64.jdk(maven地址);解决方法:Could not initialize class com.jacob.com.ComThread

Global site tag (gtag.js) - Google Analytics