Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Doubt about detached entity passed to persist

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic