我调用一个服务来加载一个实体。如果我在集成测试中运行它,这一切都很好,但在服务器上的现实生活中,它会失败。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