SSH整合报错:failed to lazily initialize a collection of role
2015-09-04 13:14
429 查看
今天整合ssh,测试Dao层方法时,本地测试了一个方法 没有问题,
然而程序部署到tomcat上时却报了一个错误:
org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role: com.etoak.bean.Adarea.ads, no session or session was closed
大概意思是延迟初始化集合失败,没有会话或会话关闭。
网上两种办法:
第一种 : 把所有onetomany mangToone 映射的属性加上lazy=”false”,但据说这种办法会让
降低查询效率 。 所以不建议采用 小编就不赘述了
第二种 : 在web.xml中添加如下:
不过要注意 同时要在ioc容器中设置sessionFactory的实体bean id为sessionFactory ,不能随意定义了。
然而程序部署到tomcat上时却报了一个错误:
org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role: com.etoak.bean.Adarea.ads, no session or session was closed
大概意思是延迟初始化集合失败,没有会话或会话关闭。
网上两种办法:
第一种 : 把所有onetomany mangToone 映射的属性加上lazy=”false”,但据说这种办法会让
降低查询效率 。 所以不建议采用 小编就不赘述了
第二种 : 在web.xml中添加如下:
<filter> <filter-name>hibernateFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
不过要注意 同时要在ioc容器中设置sessionFactory的实体bean id为sessionFactory ,不能随意定义了。
相关文章推荐
- UVa 10976:Fractions Again?!(水题)
- 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
- http://blog.csdn.net/yes_life/article/details/6831856 根文件系统设备号
- AI (Adobe Illustrator)详细用法(三)
- 完全教程 Aircrack-ng破解WEP、WPA-PSK加密利器
- 北美18名校的数据挖掘,数据分析,人工智能及机器学习课程汇总
- RAID磁盘阵列特性简介
- FAILED Task attempt_xx_r_000000_0 failed to report status for 600 seconds
- [HDOJ1022]Train Problem I
- USACO 1.3 Barn Repair
- openwrt编译error: ext4_allocate_best_fit_partial: failed to allocate 13 blocks, out of space?
- DP - hdu5009 Paint Pearls
- EMAIL之SMTP应答序列
- whx带我刷JOI training
- Contains Duplicate II -- leetcode
- 新发现:AirDroid(用Web端控制自己的手机发信息)
- 音乐播放器-MainContentActivity简析
- hdu2457 DNA repair(AC自动机+dp)
- 小议:Windows Server 2012如何部署Child Domain Controller?
- 新浪微博 AbsListView.obtainView调用关系