关于Hibernate中调用集合类时出现的 the owning Session was closed 错误解决方案

    错误异常:

08:42:43,546 error lazyinitializationexception:19 - could not initialize proxy - the owning session was closed
org.hibernate.lazyinitializationexception: could not initialize proxy - the owning session was closed
at org.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:60)
at org.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:111)
at org.hibernate.proxy.pojo.cglib.cgliblazyinitializer.invoke(cgliblazyinitializer.java:172)


解决方案:
hibernate默认是延迟加载,而导致无法将集合类中数据读取出来

则可以在相应pojo对应的hbm.xml文件里做出相关修改
1 可以在hibernate-mapping标签中设置属性default-lazy="false"
2 也可以在class标签中设置属性lazy="false"
以上都可以解决问题 

你可能感兴趣的:(java,工作)