异常:could not initialize proxy - no Session
来源:互联网 发布:重庆网上选车牌号软件 编辑:程序博客网 时间:2024/04/28 08:25
这种异常有时是因为在用Hibernate的load方法取数据库的数据时发生的,因此往往load出来的对象是一个Proxy即一个代理对象,而取出来的方法执行完毕后,session就会关闭,而当返回这个代理对象到客户端解析jsp页面时才会真正的发SQL语句,而此时的session已经关闭,因此会抛出此异常。解决方法如下:
(1)使用get方法来替代load方法,但是要注意的时若get方法的数据表若还关联了其他的对象则依然不会在get对象时发出SQL语句,依然会出现这个异常。
(2)扩大session的生命周期。即可采用Spring提供的一个filter:OpenSessionInView。
完整的filter配置如下:
<filter>
<filter-name>OpenSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:这个filter必须写在web.xml文件的filter名为struts2的前面。
(1)使用get方法来替代load方法,但是要注意的时若get方法的数据表若还关联了其他的对象则依然不会在get对象时发出SQL语句,依然会出现这个异常。
(2)扩大session的生命周期。即可采用Spring提供的一个filter:OpenSessionInView。
<filter>
</filter>
<filter-mapping>
</filter-mapping>
1 0
- 异常:could not initialize proxy - no Session
- 异常:could not initialize proxy - no Session
- 异常 could not initialize proxy - no Session 的解决方法
- could not initialize proxy - no Session 异常情况探究
- could not initialize proxy - no Session 经典异常,详解
- 异常: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- java中的异常could not initialize proxy - no Session
- 异常:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- 异常Hibernate:could not initialize proxy - no Session
- could not initialize proxy - no Session
- could not initialize proxy - no Session
- could not initialize proxy - no Session
- could not initialize proxy - no Session
- could not initialize proxy - no Session
- ERROR - could not initialize proxy - no Session
- could not initialize proxy - no session
- Hibernate: could not initialize proxy - no Session
- could not initialize proxy - no Session
- qt程序中hid问题记录
- 界面跳转设置,及定位服务
- objective-c延展类目协议
- 遥感影像处理
- 单机搭建基于Hadoop的Spark环境
- 异常:could not initialize proxy - no Session
- 简单实例NSFileHandle的文件读写
- Android文件存储位置简述
- POJ 3274 哈希
- 参数曲面计算法向量
- Item 15: 只要有可能,就使用constexpr
- oracle的jdbc连接方式:oci和thin
- typddef struct
- 一个简单的设置时间,并用两种形式显示时间。