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

错误异常:

08:42:43,546errorlazyinitializationexception:19-couldnotinitializeproxy-theowningsessionwasclosed

org.hibernate.lazyinitializationexception:couldnotinitializeproxy-theowningsessionwasclosed

atorg.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:60)

atorg.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:111)

atorg.hibernate.proxy.pojo.cglib.cgliblazyinitializer.invoke(cgliblazyinitializer.java:172)

解决方案:

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

则可以在相应pojo对应的hbm.xml文件里做出相关修改

1可以在hibernate-mapping标签中设置属性default-lazy="false"

2也可以在class标签中设置属性lazy="false"

以上都可以解决问题

相关推荐