guochao1989104
2012-12-05 11:32
浏览 391
已采纳

tomcat集群时候,报org.hibernate.LazyInitializationException

如题,项目在单一服务器上运行的时候没有问题,但是做了tomcat集群之后,出现异常:如下
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.eshore.eip.platform.persistence.entity.user.User.userBindInfos, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
at de.javakaffee.web.msm.serializer.javolution.ReflectionBinding$XMLCollectionFormat.write(ReflectionBinding.java:381)

在网上搜过之后,大部分回答是说因为HIbernate一对多关系的 一 方 使用懒加载,使得需要访问懒加载的数据时候session关闭的原因,但是我按那个方法试了没有用,希望有这方面经验的大神知道一下,小弟没有积分,所以只能按最低分数悬赏了

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • jinnianshilongnian 2012-12-05 12:08
    已采纳

    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.eshore.eip.platform.persistence.entity.user.User.userBindInfos, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
    at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
    at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
    at de.javakaffee.web.msm.serializer.javolution.ReflectionBinding$XMLCollectionFormat.write(ReflectionBinding.java:381)

        at de.javakaffee.web.msm.serializer.javolution.ReflectionBinding$XMLCollectionFormat.write(ReflectionBinding.java:381)  从这段代码可以看到你得到的数据是反序列化回来的
    

    如果你的对象有lazy 的collection 解决办法可以考虑改成非lazy的

    打赏 评论

相关推荐 更多相似问题