1 Reply Latest reply on Sep 11, 2013 11:46 AM by Radim Hanus

    Extended persistence context : unexpected detached entities

    Yan Langlois Newbie

      I have a probleme which looks like the one here : Re: Unexpected detached entities with extended persistence context. But In my case I do not have any rollback to explain the detached entities. Here is my case :

       

      I have un a producer which uses a extended persistence context, It first gets a list of entities and then for each one I try to find the the object with the EntityManager.find method :

       

      @ConversationScoped

      public class MyProducer implements Serializable {

          @PersistenceContext(unitName="primary", type=PersistenceContextType.EXTENDED)

          private EntityManager em;

         

          @PostConstruct

          public void init() {

              List<MyEntity> list = em.createQuery("From MyEntity").getResultList();

              for (MyEntity e : list) {

                  MyEntity e2 = em.find(MyEntity.class, e.getId());

                  logger.severe(Boolean.valueOf(e == e2));

              }

       

          }

       

      }

       

      If I understand detached entities well (http://docs.oracle.com/cd/E24329_01/apirefs.1211/e24396/ejb3_overview_emfactory_perscontext.html), entity "e" and "e2" should be the same. But there are not. I notice that a class in JBoss7 called org.jboss.as.jpa.container.QueryNonTxInvocationDetacher (from org.jboss.as/jboss-as-jpa/7.1.0.Final) detach all entities without checking the PersistenceContextType of the entityManager :


      @Override

      public List  [More ...] getResultList() {

          List result = underlyingQuery.getResultList();

          //The purpose of this wrapper class is so that we can detach the returned entities from this method. Call EntityManager.clear will accomplish that.

          underlyingEntityManager.clear();

          return result;

      }

       

      Is it a bug ?

      Is it possible to get managed entities with a extended persistence context in my case (I mean without transaction) ?