我調用一個服務來加載一個實體。如果我在集成測試中運行它,這一切都很好,但在服務器上的現實生活中,它會失敗。jpa lazyloading在生產模式下失敗 - 在testmode中工作正常
此實體中的一些屬性是集合。該實體在兩種情況下都加載了bean。當我在「query.getSingleResult()」附近的斷點處停止debugmode中的執行時,我看到集合已加載。但只有在一個testrun ...
我停止在servletcontainer中的相同的代碼,並得到一個InvocationException!?
我的環境look's像:
春季3.1
冬眠3.6.6.Final
東西我曾嘗試:
- 搜索中的context.xml(試生產)
差異 - 使用其他context.xml文件(測試)在productionmode
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.hoeso.gwt.platform.server.domain.common.Person.anschrift, 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.hoeso.sis.server.services.common.impl.UserServiceBeanImpl.login(UserServiceBeanImpl.java:397) at de.hoeso.sis.server.rpc.LoginService.execute(LoginService.java:35)
我發現,在測試模式的HIB ernate會話已連接並打開。在productionmode(在servletcontainer存在通過entitymanager.getDelegate()
沒有可用的連接hibernatesession。
您的測試方法是否將兒童加載到事務中? – JMelnik
「,並得到一個InvocationException」爲InvocationException添加堆棧跟蹤的副本可能有助於人們回答你的問題。測試和生產bean配置有什麼不同? – Raedwald
@JMelnik:這是同一筆交易。我加載實體,下一行代碼出現此錯誤。 – ChangeRequest