Results 1 to 1 of 1
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default 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 11:14 AM.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Replies: 0
    Last Post: 07-22-2011, 01:47 PM
  2. front end display of field description when clicking the field name
    By neils in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-29-2010, 12:47 PM
  3. Replies: 1
    Last Post: 10-25-2010, 01:20 PM
  4. java -version pointing to older version
    By deepakts in forum New To Java
    Replies: 4
    Last Post: 05-06-2010, 10:59 AM
  5. Replies: 4
    Last Post: 01-18-2010, 12:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •