2 Replies Latest reply on Jul 15, 2014 6:09 AM by mvitorovic

    Entity getting detached inside transaction

    mvitorovic

      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

        • 1. Re: Entity getting detached inside transaction
          wdfink

          Which version of WildFly do you use?

          How do you see that the Entity is detached? Could you provide a bit more details?

          1 of 1 people found this helpful
          • 2. Re: Entity getting detached inside transaction
            mvitorovic

            What can I say We were definitely seeing this sort of behavior (adding logging said that the entity is detached), but were in a hurry at the time, worked around it, and now I cannot reproduce it. We did a couple of changes in between, so obviously this fixed the bug. And apparently it was our bug which we couldn't locate to begin with.

             

            Sorry for the noise, and thank you for reacting so quickly.

             

            P.S.: the AS is WildFly 8.1.0 Final, RDBMS is PosgreSQL 9.2.

             

            Miha