5 Replies Latest reply on Aug 18, 2006 10:18 AM by Taras Tratatata

    What is the best way to re-attach a detached entity?

    None None Master

      I have an object called customer. I'm using Seam, and an EntityManager is injected, and a customer object is successful injected. I try to merge the customer back like this:

      entityManager.merge(customer);

      but that does not work, because after that, I do:

      if(! entityManager.contains(customer)) log.severe("Oh no it did not work");

      Of course, it logs that the entityManager does not contain the customer.

      What is the best way to re-attach a detached entity?

      Should I do:

      customer = entityManager.find(Customer.class, customer.getId());

      ?

      That seems like it would re-attach, but surely there is some method within EntityManager to re-attach a detached entity without doing a find on it?