openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fay Wang (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-1004) Derived Identity fails when parent id is auto-generated
Date Mon, 30 Mar 2009 23:35:51 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693940#action_12693940
] 

Fay Wang commented on OPENJPA-1004:
-----------------------------------

The PCEnhancer generates pcCopyKeyFieldsToObjectId as following:

  public void pcCopyKeyFieldsToObjectId(Object paramObject)
  {
    Object localObject;
    ChildId localChildId = (ChildId)((ObjectId)paramObject).getId();
    localChildId.id = this.id;
    Parent localParent = this.parent;
    if (localParent != null)
      localObject = ((PersistenceCapable)localParent).pcFetchObjectId();
    localChildId.parent = ((localObject != null) ? ((LongId)localObject).getId() : 0L);
  }

Since the parent has generated key, its objectId is null during pre-flush stage, the parent.pcFetchObjectId
will throw the exception: 

<openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.InvalidStateException:
Detected reentrant flush.  Make sure your flush-time instance callback methods or event listeners
do not invoke any operations that require the in-progress flush to complete.
    at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1904)
    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
    at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:524)
    at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:506)
    at org.apache.openjpa.kernel.StateManagerImpl.fetchObjectId(StateManagerImpl.java:1434)
    at net.company.persistence.Parent.pcFetchObjectId(Parent.java)
    at net.company.persistence.Child.pcCopyKeyFieldsToObjectId(Child.java)

The proposed fix is to have PCEnhancer generate the following code when parent has generated
key:

  public void pcCopyKeyFieldsToObjectId(Object paramObject)
  {
    ChildId localChildId = (ChildId)((ObjectId)paramObject).getId();
    localChildId.id = this.id;
    localChildId.parent = 0L;
  }

The test case then passed.

> Derived Identity fails when parent id is auto-generated
> -------------------------------------------------------
>
>                 Key: OPENJPA-1004
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1004
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.2.2, 2.0.0
>            Reporter: Fay Wang
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message