2 Replies Latest reply on Jul 15, 2014 6:09 AM by Miha Vitorovič

    Entity getting detached inside transaction

    Miha Vitorovič Newbie

      Hi,

       

      I have the following situation:

       

      @Stateless class A {
            @Inject B b;
      
            public void doSomething() {
               Entity x = b.get(); // Entity is getting detached here
               b.remove(x);
            }
      }
      
      @Stateless class B {
            @PersistenceContext EntityManager em;
      
            public Entity get() { return em.find(....); }
            public void remove(Entity e) { em.remove(e); }
      } 
      

      I was under the impression that the entity is associated with the EntityManager for the entire duration of the transaction (and that is how I understand tha JPA specs as well), but that appears not to be the case. What is going on in this case?

       

      Thanks for your input.

       

      Miha