| Author |
Doubt about detached entity passed to persist
|
Frederico Benevides
Greenhorn
Joined: Jan 15, 2006
Posts: 25
|
|
I load my object A, when I try to persist even I changed the Id of the object I got this exception. When I change to merge I don't get. So even my object is detached from the container, the container still has reference to this object? How long the container will have this reference?
|
 |
Shivani Chandna
Ranch Hand
Joined: Sep 18, 2004
Posts: 380
|
|
Hello Frederico, I have not understood your question correctly, Could you please re-frame it? When a detached entity is passed for persistence the entity becomes managed until the end of transaction (If the persistence context has the type defined as transaction). For merge - the copy of the object is created and then a managed entity is returned. If the managed entity exists before then it is updated or else a new one is created and returned to the client. Regards, Shivani
|
/** Code speaks louder than words */
|
 |
Frederico Benevides
Greenhorn
Joined: Jan 15, 2006
Posts: 25
|
|
Hello, thank for your answer. I'll explain with examples. When I'm on the client and use remote session beans to find my "Person entity": So I would like to understand how the container knows the the object Person that I find one "day" was managed or attached to him. I changed the Id just to test if it would let me to attach just to think as "new object". But not. I can't. Since I'm using remote, and my method calls finished, why the container knows that object need to attached again, and don't let me add as a new object. So I think the container has a reference to this object that I find even I finished the method's call.
|
 |
Shivani Chandna
Ranch Hand
Joined: Sep 18, 2004
Posts: 380
|
|
Hello Frederico, I created a Stateless session bean named ManagePerson with methods save,find, update.And Person entity class with fields id and name. In save method of I called entityMgrObject.persist(personObj); So, for me a new record does get created on persist. Now ,could you please share your complete code so that I can see where the problem is? Regards, Shivani
|
 |
 |
|
|
subject: Doubt about detached entity passed to persist
|
|
|