title: getResultList() in init-method giving error "session is closed"
body: <p>I am trying to load some data from DB in the init method of my service class but when I call the "getResultList()" method then it throws an Exception "Session is closed".</p>
  
  <p>my applicationContext.xml</p>
  
  <pre><code>&lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;    
  &lt;bean id="testService" class="com.impl.TestServiceImpl" init-method="init" /&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p>my service class:</p>
  
  <pre><code>public Class TestServiceImpl implements TestService {
  private EntityManager entityManager;
  
  @PersistenceContext
  public void setEntityManager(EntityManager entityManager) {
     this.entityManager = entityManager;
  }   
  
  public void init() {
      Query query = entityManager.createQuery("from myTable");
      query.getResultList();  // this causes error...
  }
  }
  </code></pre>
  
  <p>This is the error message:</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class 
  org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
  'testService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: 
  Invocation of init method failed; nested exception is
  javax.persistence.PersistenceException: org.hibernate.SessionException: Session is 
  closed!
  Caused by: javax.persistence.PersistenceException: org.hibernate.SessionException: 
  Session is closed!
  at 
  org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
  </code></pre>
  
  <p>So what I am doing wrong here? How can I solve this issue? Thanks.</p>