OpenJPA
  1. OpenJPA
  2. OPENJPA-2142

Merge of a new object does not handle Entity Id field

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 2.3.0
    • Fix Version/s: 2.2.1, 2.3.0
    • Component/s: None
    • Labels:
      None

      Description

      When a merge is done on a new object with an Id that contains an Entity, the following exception occurs:

      <openjpa-2.2.1-SNAPSHOT-r422266:1292578 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: Attempt to change a primary key field of an instance that already has a final object id. Only new, unflushed instances whose id you have not retrieved can have their primary keys changed.
      FailedObject: hat.entities.Child@38d138d1
      at org.apache.openjpa.kernel.StateManagerImpl.assertNoPrimaryKeyChange(StateManagerImpl.java:2108)
      at org.apache.openjpa.kernel.StateManagerImpl.settingObjectField(StateManagerImpl.java:2043)
      at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:236)
      at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:155)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:252)
      at org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:370)
      at org.apache.openjpa.kernel.AttachStrategy.replaceList(AttachStrategy.java:431)
      at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:255)
      at org.apache.openjpa.kernel.AttachManager.handleCascade(AttachManager.java:267)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:105)
      at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3474)
      at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1214)
      at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:878)
      ...

      During the merge, a copy is made of the original object, with a copy of the key fields. But, if a key field is an Entity, it is not copied, causing this exception in later processing. The fix is to attach this field immediately after the original object is copied.

        Activity

        Dianne Richards created issue -
        Dianne Richards made changes -
        Field Original Value New Value
        Status Open [ 1 ] In Progress [ 3 ]
        Dianne Richards made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Dianne Richards made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Dianne Richards added a comment -

        Reopen to commit changes for earlier releases

        Show
        Dianne Richards added a comment - Reopen to commit changes for earlier releases
        Dianne Richards made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Hide
        Dianne Richards added a comment -

        In 2.0.x there is a 2nd problem in this merge scenario. BrokerImpl.getObjectId() returns null when the StateManager in the pc object is null. This is fixed in subsequent releases by calling ApplicationIds.create(). This fix will be backported to 2.0.x in this JIRA to complete the merge fix.

        Show
        Dianne Richards added a comment - In 2.0.x there is a 2nd problem in this merge scenario. BrokerImpl.getObjectId() returns null when the StateManager in the pc object is null. This is fixed in subsequent releases by calling ApplicationIds.create(). This fix will be backported to 2.0.x in this JIRA to complete the merge fix.
        Hide
        Rick Curtis added a comment -

        Can you also port the testcases from trunk to 2.2.x ?

        Thanks,
        Rick

        Show
        Rick Curtis added a comment - Can you also port the testcases from trunk to 2.2.x ? Thanks, Rick
        Dianne Richards made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Dianne Richards made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        13m 22s 1 Dianne Richards 24/Feb/12 15:57
        In Progress In Progress Resolved Resolved
        13d 22h 51m 1 Dianne Richards 09/Mar/12 14:49
        Closed Closed Reopened Reopened
        46d 23h 25m 1 Dianne Richards 25/Apr/12 14:15
        Reopened Reopened Resolved Resolved
        13d 10m 1 Dianne Richards 08/May/12 14:25
        Resolved Resolved Closed Closed
        42s 2 Dianne Richards 08/May/12 14:26

          People

          • Assignee:
            Dianne Richards
            Reporter:
            Dianne Richards
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development