Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about detached entity passed to persist

 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic