码迷,mamicode.com
首页 > 其他好文 > 详细

延迟加载问题

时间:2014-10-21 12:23:22      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   sp   数据   2014   on   

DAO返回一个代理对象,在service中 关闭事务,web层获得一个脱管态对象,当访问对象中数据时,发生异常 

bubuko.com,布布扣



解决方案一: 返回有数据的对象 
public Product searchProduct(int id) {
Product product = productDAO.findById(id);
// 调用代理对象数据,在session关闭前 初始化
product.getName();
return product;
}


解决方案二: OpenSessionInView  在视图层打开Session 
Spring 提供Filter 可以将事务管理放到web层 


  <filter>
  <filter-name>openSessionFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>openSessionFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>

延迟加载问题

标签:style   blog   http   io   ar   sp   数据   2014   on   

原文地址:http://blog.csdn.net/u012815721/article/details/40341499

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!