Results 1 to 1 of 1
Thread: JPA merge and @Version field
- 07-30-2011, 05:34 AM #1
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.
Last edited by kjkrum; 07-30-2011 at 10:14 AM.Get in the habit of using standard Java naming conventions!
- By gadek.a in forum LuceneReplies: 0Last Post: 07-22-2011, 12:47 PM
- By neils in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-29-2010, 11:47 AM
- By eel in forum NetworkingReplies: 1Last Post: 10-25-2010, 12:20 PM
- By deepakts in forum New To JavaReplies: 4Last Post: 05-06-2010, 09:59 AM
- By lse123 in forum Java ServletReplies: 4Last Post: 01-17-2010, 11:13 PM