Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Merge Vs Persist with respect to removed entity  RSS feed

 
Sudhanshu Mishra
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.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2921
205
Android Chrome Eclipse IDE
  • 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().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!