So, as outlined in :
Automatic State Detection
I understand that during a merge, the given instance is not reattached to the persistence context, but is instead returned by the merge operation. In the context of an update to an existing entity rather than persisting a new entity, I can understand this rational.
However, one point in the documentation discussed here:
Transitive persistence
says that cascading on ManyToOne/ManyToMany relationship doesn't really make sense, however it is acceptable to say, cascade merges and persists only to save yourself some typing.
In my case, I have objects with ManyToOne relationships. In the event that the parent object is a new object, the ManyToOne relationships may or may not already exist, thus I need the insert-or-update semantics of merge rather than persist. What bothers me is the semantics of adding a new entity and having to return the result from the merge operation (so that I have autogenerated id's and such).
I understand why this is necessary, but I'm wondering if there is a way to reattach the given instance to the persistence context during a merge (i.e. how persist works) without having to return the object returned by merge().
Any thoughts??
Thanks in advance!
Justin[/url]