This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Merge Vs Persist with respect to removed entity

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Why does a persist method on a removed instance makes it managed , while a merge operation on a removed instance throws an exception.
I am confused as the spec says that a removed instance is still associated with the persistence context.
So why different behavior from persist and merge on a removed entity?
Basic confusion is how to decide when a particular operation will throw an exception.Can we decide it on the basis of an ID conflict , or on the basis of presence of a persistence context?

Thanks
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help.
 
Creator of Enthuware JWS+ V6
Posts: 3289
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is just what the specifications specify, but I guess you were not asking for such an answer. Just look at it like this: persist on a removed instance is a sort of "undo my previous removal".

Merging detached state into a removed instance just sounds strange, why would you do that? What is the practical use? If you really want this kind of feature you can still manage to do it by the sequence of em.persist() and em.merge().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!