users@glassfish.java.net

Re: Problem with Toplink Cache & parallel access of 2 servlets

From: <glassfish_at_javadesktop.org>
Date: Fri, 12 Feb 2010 06:20:14 PST

Hello Encey,

Entities are never automatically reattached, as detaching means the context no longer has a referene to the entity. By automatically detaching at the end of a method, I assume you are refering to the scope of an entitymanager or transaction when using injection. If so, this means the transaction is either commited or rolledback, and the container will obtain a new EntityManager - the new EM will not have any references to entities held in the old one (which is also likely closed), so they are effectively detached. Passing them in as parameters cannot tell the EntityManager they are back - calling EntityManager.merge on them will merge the changes into the managed copy. So what you could instaed be seeing is that the scope is longer than the method you are using, and so the entity is not really detached when it ends - for instance if it is all in one larger transaction, the container would have you use one EntityManager for the entire transaction.

Best Regards,
Chris
[Message sent by forum member 'chris_delahunt' (christopher.delahunt_at_oracle.com)]

http://forums.java.net/jive/thread.jspa?messageID=386374