获取 org.hibernate.HibernateException:集合不与任何会话关联



我在数据库中获取表中存在的所有条目时遇到异常。

我收到的错误是:

org.hibernate.HibernateException: collection is not associated with any session
        at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:678) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:893) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:360) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2554) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2540) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]

令我震惊的是,我在测试过程中没有收到此错误,但它出现在生产环境中,这让我感到困惑!

这里有人可以帮助我弄清楚这种奇怪的行为吗?

它与桌子的大小有关吗?

将@Transactional注释放在方法的顶部。

最新更新