JPA merge and @Version field
My JPA app uses detached entities, as described under the merge() section of this page. When their state is modified, I merge them into a new persistence context and commit it. merge() returns a reference to a managed copy of the original object, which becomes detached when the transaction commits. I return the new copy to the caller.
Now, the caller *should* replace all their references to the original object with references to the new copy. But I'd like it if they didn't have to.
Am I correct in thinking that if the merge is successful, then the only difference between the state of the old object and the state of the new object is the value in the @Version field? Is it safe for me to simply copy that value from the new object to the old object, and let the caller keep using the old object?
Edit: In the case of new objects, the merged copy has also been assigned its @Id.