7 Replies Latest reply on Mar 11, 2009 11:45 AM by Stuart Douglas

    why EntityManager is closed?

    Alexey Kopylov Newbie

      I have POJO session-bean with:


      @Scope(ScopeType.SESSION)



      In this bean I have a property of:


      EntityQuery<something>



      This property I use to fill a datatable: values in resultList. This is standard decision I think.


      My question is EntityManager about which located in this EntityQuery. When I create an object of the EntityQuery in my bean I can get resultList correctly. It works without errors.


      But... Later in some method of the bean I want to refresh data of the EntityQuery. I want to refresh data using refresh method. And this method returns null of resultList because EntityManager is closed by this time. Hmm... To avoid this problem I must use this trick:



              if (!mfoPeriodList.getEntityManager().isOpen())
              {
                  EntityQuery query = new EntityQuery();  
                  EntityManager em = query.getEntityManager();
                  mfoPeriodList.setEntityManager(em);            
              }
              mfoPeriodList.refresh();



      Looks not good but I don't know how to do it better.
      Why EntityManager is closed in my EntityQuery? Is it bug or feature of EntityQuery? How to work with it correctly if I need to refresh data in some method?


      BTW... The same situation if I use extending EntityController instead of POJO. Please explain how to avoid closing of EntityManager in the bean.


      P.S.: Seam 2.1.1, Jboss 4.2.3


      Thanks.