OpenJPA
  1. OpenJPA
  2. OPENJPA-1873

EntityManager#merge sometimes passes wrong entity values to @PostLoad EntityListeners

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0, 2.0.1, 2.0.2
    • Fix Version/s: 2.2.0
    • Component/s: kernel
    • Labels:
      None

      Description

      I've tested this with the latest from branches/2.0.x.

      My entity has an @EntityListeners which observes the @PostLoad lifecycle event. This listener stores the 'old' values from the database for later use (see http://struberg.wordpress.com/2010/07/31/howto-changelog-with-jpa/ for the intention behind). All works well if the table has only a few rows. But if you add more rows, OpenJPA tries to optimize the access and only loads the @Version field + the dirty fields. In this case the merging seems to be wrong, because I get the NEW values from the dirty fields instead of the original values from the database passed to my @PostLoad method.

      Did cost me a few grey hairs to track down the differences between the working and the broken scenarios here But finally I was able to creat a unit test showing the problem

      1. OPENJPA-1873-fix3.patch
        27 kB
        Mark Struberg
      2. OPENJPA-1873-fix2.patch
        24 kB
        Mark Struberg
      3. OPENJPA-1873-fix1.patch
        17 kB
        Mark Struberg
      4. openjpa-1873-hack-1.patch
        3 kB
        Rick Curtis
      5. postloadtest.zip
        11 kB
        Mark Struberg
      6. OPENJPA-1873-unittest.patch
        9 kB
        Mark Struberg

        Activity

        Mark Struberg created issue -
        Mark Struberg made changes -
        Field Original Value New Value
        Attachment OPENJPA-1873-unittest.patch [ 12458842 ]
        Mark Struberg made changes -
        Attachment postloadtest.zip [ 12459166 ]
        Rick Curtis made changes -
        Assignee Rick Curtis [ curtisr7 ]
        Rick Curtis made changes -
        Attachment openjpa-1873-hack-1.patch [ 12467741 ]
        Mark Struberg made changes -
        Attachment OPENJPA-1873-fix1.patch [ 12467779 ]
        Mark Struberg made changes -
        Attachment OPENJPA-1873-fix2.patch [ 12467792 ]
        Mark Struberg made changes -
        Attachment OPENJPA-1873-fix3.patch [ 12506498 ]
        Mark Struberg made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.0 [ 12315910 ]
        Resolution Fixed [ 1 ]
        Kevin Sutter made changes -
        Assignee Rick Curtis [ curtisr7 ] Mark Struberg [ struberg ]
        Albert Lee made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Mark Struberg
            Reporter:
            Mark Struberg
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development