Hibernate异常Collection与任何会话无关

时间:2013-05-15 15:04:55

标签: java hibernate exception persistence

所以,我有一个实体,比如 Entity1 ,它与另一个实体 Entity2 连接。反过来,Entity2与另一个实体 Enitity3 联接。

我有Entity1.entity2加入,因为 OneToMany 因此返回一个List。在Entity2.entity3中也是如此,它也是 OneToMany 并返回一个List。

现在我正在构建一个Web服务,我在其中调用Enitity1然后加载entity2 (i.e. List<Entity2> entity2 = entity1.getEntity2())

对于每个entity2,我加载entity3 (i.e. List<Entity3> entity3 = entity2.getEntity3())

第一次正确运行查询,但当它尝试从Entity3 entity2中获取(i.e. List<Entity3> entity3 = enity2.get(1).getEntity3())时,它会抛出上述异常:

Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: collection is not associated with any session
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1179)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1112)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:245)
at com.test.test.adapter.impl.TestDbAdapterImpl.getTestList(TestDbAdapterImpl.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
... 86 more

0 个答案:

没有答案