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

Robert Zeigler commented on CAY-1183:
-------------------------------------

The pseudocode looks suspicious to me (not saying there's not an issue with 
cayenne, I just want to clarify the pseudocode first):

You're selecting the artist from the /parent/ context (so it should be 
registered with the parent context). 
Then you're creating the painting from the /child/ context.
Then you're setting the artist relationship of the painting (associated with 
child context) to be the artist you previously queried (associated with the 
parent context).  Unless something has changed recently that I'm unaware of, 
the code above should blow up there, due to associating objects of different 
contexts together...?

The normal paradigm would be:
  artist = childContext.localObject(artist.getObjectId(),artist);
  Painting painting = childContext.newObject(Painting.class);
  painting.setArtist(artist);
  painting.setBlah...
  childContext.commitToParent();

  painting = parentContext.localObject(painting.getObjectId(),null);

  //now try:
  painting.getSomeRelationship();



> commitToParent() makes object persistence state committed, produces exception 
> when using object in parent context (ROP)
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAY-1183
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1183
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0M5
>         Environment: ROP (maybe also 2t cayenne, I have not tried)
>            Reporter: Marcin Skladaniec
>            Priority: Critical
>
> This is a bit of pseudocode showing the problem
> Artist artist = parentContext.perfrormQuery(new 
> SelectQuery(Artist.class)).get(0);
> CayenneContext childContext = parentContext.createChildContext();
> Painting painting = childContext.newObject(Painting.class);
> painting.setArtist(artist);
> painting.setBlah...
> childContext.commitToParent();
> for(Painting p : artist.getPaintings()) 
> logger.debug("painting persistence state : 
> "+PersistenceState.persistenceStateName(p.getPersistenceState())); //all 
> objects are in state COMMITTED
> this causes no problems so far, but if one now decides to 
> p.getSomeRelatiohship();
> an exception will be raised, because the relationship has not been faulted 
> yet:
>  [java] Caused by: java.lang.Exception: [v.3.0-SNAPSHOT ${project.build.date} 
> ${project.build.time}] Can't build a query for relationship 
> 'someRelationship' for temporary id: <ObjectId:Painting, 
> TEMP:00000160F3600029>
>      [java]   at 
> org.apache.cayenne.remote.service.BaseRemoteService.processMessage(BaseRemoteService.java:160)
>   ... 25 more

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

Reply via email to