关于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,xml,Hibernate)