[jboss-user] [EJB 3.0] - What is the best way to re-attach a detached entity?

SmokingAPipe do-not-reply at jboss.com
Fri Aug 18 02:02:14 EDT 2006


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?


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3965945#3965945

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3965945



More information about the jboss-user mailing list