[ 
https://issues.apache.org/jira/browse/CAY-1807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13631730#comment-13631730
 ] 

Manuel Sánchez Ortiz commented on CAY-1807:
-------------------------------------------

1) Yes. The object is new
org.apache.cayenne.access.DataDomainDBDiffBuilder.arcDeleted(DataDomainDBDiffBuilder.java:183)
org.apache.cayenne.access.ObjectDiff$ArcOperation.apply(ObjectDiff.java:440)
org.apache.cayenne.access.DataDomainDBDiffBuilder.buildDBDiff(DataDomainDBDiffBuilder.java:76)
org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:80)
org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:79)
org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:182)
org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:134)
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1106)
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)
.....
My code:

NuxPropertyType oldPTypeAutoAssignedOnPostAdd= toItem.getRelPropertyType();
if( oldPTypeAutoAssignedOnPostAdd != null ){
//disconect it
toItem.setRelPropertyType(null);  //needed to avoid NPE
//an remove it
toItem.getObjectContext().deleteObject(oldPTypeAutoAssignedOnPostAdd);
                        }
                        toItem.setRelPropertyType(toPType);

Avoiding a NPE and saying something more practical is good improvement.

Thanks



On Mon, Apr 15, 2013 at 1:46 PM, Andrus Adamchik (JIRA) <[email protected]>wrote:


                
> Replace a Detached object  with new one on a relationship throws NPE
> --------------------------------------------------------------------
>
>                 Key: CAY-1807
>                 URL: https://issues.apache.org/jira/browse/CAY-1807
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library
>    Affects Versions: 3.0.1
>            Reporter: Manuel Sánchez
>            Priority: Minor
>
> In the following scenario:
> I deleted and persistent object (gets detached) which was used in a 
> relationship
> I replaced it with a new one at the end of a relathionship
> Cayenne records an ArcDeletedOperation with the detached object involved and 
> throws a NPE when commiting.
> I solved the problem by disconecting the detached object from the 
> relationship (set to null) and then assigning the new one; in two steps
> Cayenne could check if its a detached object on that ArcDeletedOperation and 
> say so instead of throwing a NPE, or not recording any action, .. something 
> more elegant than a NPE
> Thanks

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to