您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Java >> Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed

Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed

来源:网络整理     时间:2016/8/16 16:47:35     关键词:

关于网友提出的“ Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed”问题疑问,本网通过在网上对“ Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed
描述:

我用Hibernate检索多对一的关系,总是报错:   
  Could   not   initialize   proxy   the   owning   session   was   closed   
    
  例如:Order   多对一于   Custom   ,   
  通过Order.CustId对应   Custom.id   
    
  当取出指定id的Order后:   
  order   =   session.get(Order.class,id);   
  通过   
  custom   =   order.getCustom();   
  custom.getName();   
    
  然后commit;   
    
  可以确定数据库执行了查询Order表和Custom表的两条语句。   
  执行custom.getId();   
  也可以得出正确的ID。   
  我将上述代码封装到BEAN里。   
    
  问题是Custom的值总是未实例化,   
  在MyEclipse里调试可以看到它的值有   
  Custom$$EnhanceByCGIB$$452342   
  CGLIBLazyInitializer   
  ...   
  等信息,   
  即未实例化。   
  而Order有实在的各个值。   
    
  将Custom存储到request对象中,下一页面访问就报错:   
  Could   not   initialize   proxy   the   owning   session   was   closed   
    
  Custom.hbm.xml     
  class元素无论设置   lazy是否等于true都一样。   
    
    
  怎么解决?


解决方案1:

把lazy=false写上,应该就可以了,不然默认要经过代理proxy


以上介绍了“ Hibername延迟检索问题?lazy ,Could not initialize proxy the owning session was closed”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3330794.html

相关图片

相关文章