3 Replies Latest reply on Nov 6, 2008 5:14 PM by Anil Erukala

    2.1.0.BETA1: IllegalStateException: EntityManager is closed

    Vladimir Kovalyuk Apprentice

      Sympthoms:


      page contains <h:selectOneMenu> with <s:convertEntity> within. It displays correctly for the first time. But when the user selects an instance and submits the form the IllegalStateException occurs. It tells that EntityManager is closed. Performed brief investigation on that matter I figured out that:


      2.1.0.A1 had EntityLoader class with overriden method


         @Override
         public EntityManager getPersistenceContext()
         {
            if (!super.getPersistenceContext().isOpen())
               super.setPersistenceContext(null);
            return super.getPersistenceContext();
         }



      2.1.0.BETA1 has JpaEntityLoader which does not have such a method overriden and the following code works:



      public abstract class PersistenceController<T> extends Controller
      {
         private transient T persistenceContext;
         
         public T getPersistenceContext()
         {
            if (persistenceContext==null)
            {
               persistenceContext = (T) getComponentInstance( getPersistenceContextName() );
            }
            return persistenceContext;
         }
      
      


      As the result when page is rendered jpaEntityLoader contains opened entityManager. After submit when processing validations it remembers stale persistence context and returns it. Persistence context has been already closed so that's the cause of the problem.


      Proceed with JIRA?