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.
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?
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().