2 Replies Latest reply on Aug 22, 2006 12:07 AM by treespace

    Need advice on refreshing @Version column

      I need to merge changes an entity instance multiple times. The second merge causes an optimistic lock failure unless I "manually" update the version string:

      original.setVersion( em.merge( original ).getVersion() );

      I cannot use the updated entity returned from merge because I have many reference to the original instance in several lists.

      Calling em.refresh( original ) after em.merge( original ) did NOT update the @Version column. Why doesn't refresh update the version column?

        • 1. Re: Need advice on refreshing @Version column

          Because your original is probably detached.

          • 2. Re: Need advice on refreshing @Version column

            Sure, it's detached but it's passed to a session bean that calls merge then refresh. Refresh does not return an up-to-date instance as merge does; it simply sync's the database record with the instance you passed as an argument.

            Insofar as the only difference between the original and the merged entity is the version string (notwithstanding triggers that might change state) I assume my solution is correct: just transfer the new version number from the merge return entity to the original. It just feels icky.