How are you building the child key? Are you using KeyFactory.Builder?

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html

<http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html>You'll
have to build a key for the parent, then call .addChild(). Try a
getObjectById() afterwards.

On Thu, Jun 3, 2010 at 11:08 PM, Didier Durand <[email protected]>wrote:

> Hi,
>
> I made a very simple test case  for 1to1 owned relationship:
>
> 1 child object with a String as key
> 1 parent object with a Key as key and the child as additional property
>
> At compile time and run time, the DS does not complain for such a
> construct altough
> http://code.google.com/appengine/docs/java/datastore/relationships.html#Owned_One_to_One_Relationships
> states "The child class must have a key field whose type can contain
> the parent key information: either a Key, or a Key value encoded as a
> string. See Creating Data: Keys for information on key field types."
>
> Even more surprising (to me):
>     - the DS will automatically store the child when doing
> pm.makePersistent() on the parent.
>     - This is ok as such: as per specs, DS stores child automatically
> when persisting parent
>     - BUT, the child object is not accessible alone through
> pm.getObjectById() on the child. It is only accessible via a getter on
> the parent property storing the reference to the child.
>
> So, the child object is there not as an autonomous entity: it seems
> embedded in the parent.
>
> It seems like the DS is treating the child as an @Embedded class even
> tough the class definition of the child is not embedded in the parent
> but has its own class definition in a separate class.
>
> What reinforces this is that the key of the child is the one that I
> defined when creating it not the usual string structure "key_parent/
> key_child" with concatenation of parent_key to child_key to allow the
> DS to retrieve the child as part of entity group defined by parent.
>
> If I understood everything correctly, and according to the class
> definitions that  I made,  the child should have key of structure
> "key_parent/key_child" and be autonomous in the DS.
>
> What did I miss ?
> regards
> didier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
Blog: http://googleappengine.blogspot.com
Twitter: http://twitter.com/app_engine
Reddit: http://www.reddit.com/r/appengine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to