title: Hibernate exception Collection is not associated with any session
body: <p>So, I have an entity, say <strong>Entity1</strong> which is in join with another entity, <strong>Entity2</strong>. Entity2 in turn, is in join with another entity, <strong>Enitity3</strong>.</p>
  
  <p>I have Entity1.entity2 join as <em>OneToMany</em> therefore returns a List. The same in Entity2.entity3, it's also as <em>OneToMany</em> and returns a List.</p>
  
  <p>Now I'm building a web service in which I call Enitity1 then i load entity2 <code>(i.e. List&lt;Entity2&gt; entity2 = entity1.getEntity2())</code>.</p>
  
  <p>And for each entity2 i load entity3 <code>(i.e. List&lt;Entity3&gt; entity3 = entity2.getEntity3())</code></p>
  
  <p>The first time it runs the query correctly, but when it tries to get <code>Entity3</code> out of <code>entity2</code> <code>(i.e. List&lt;Entity3&gt; entity3 = enity2.get(1).getEntity3())</code> it throws the exception mentioned above:</p>
  
  <pre><code>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
  </code></pre>