[appengine-java] Setting the key of a child entity

2010-02-04 Thread Manny S
I am missing something simple here but can anyone point me to how I can set
the child key before making the parent data persistent...(in a
unidirectional one to one relationship)

I create the parent data and the child data

parentdata pdata = new parentdata('x','y', 'z');
pdata.setKey(null);
childdata child = new childdata('A');
pdata.setChild(child);

Now, I would like to set the child key as parent key + mystring

When I try,
String strparentKey = KeyFactory.keyToString(pdata.getKey());
String strchildKey = strparentKey + "details";
Key childKey = KeyFactory.stringToKey(strchildKey);

it gives me an error as the parent data does not have a key yet (cause is
null)

In this case the key of the parent is generated only when I persist. But I
need to set the child key before I make it persistent. My application cannot
generate an unique app id and I rely on the datastore to do it. As far as I
can tell the KeyFactory.Builder does not have an option to generate unique
keys and relies on the app to provide it and so I cant use that either.

Any help would be appreciated...

Manny

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Setting the key of a child entity

2010-02-11 Thread Ikai L (Google)
Are both the parent and child persisted at the same time? If so, you can add
the child object as a child (not the Key) of the Parent object and call
makePersistent on the Parent.

On Thu, Feb 4, 2010 at 1:28 AM, Manny S  wrote:

> I am missing something simple here but can anyone point me to how I can set
> the child key before making the parent data persistent...(in a
> unidirectional one to one relationship)
>
> I create the parent data and the child data
>
> parentdata pdata = new parentdata('x','y', 'z');
> pdata.setKey(null);
> childdata child = new childdata('A');
> pdata.setChild(child);
>
> Now, I would like to set the child key as parent key + mystring
>
> When I try,
> String strparentKey = KeyFactory.keyToString(pdata.getKey());
> String strchildKey = strparentKey + "details";
> Key childKey = KeyFactory.stringToKey(strchildKey);
>
> it gives me an error as the parent data does not have a key yet (cause is
> null)
>
> In this case the key of the parent is generated only when I persist. But I
> need to set the child key before I make it persistent. My application cannot
> generate an unique app id and I rely on the datastore to do it. As far as I
> can tell the KeyFactory.Builder does not have an option to generate unique
> keys and relies on the app to provide it and so I cant use that either.
>
> Any help would be appreciated...
>
> Manny
>
> --
> 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> 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
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Setting the key of a child entity

2010-02-14 Thread Manny S
Thanks Ikai,
I am doing it the way you described and it does work. Just wanted to know if
there is a way to set the child key explicitly as parent + "const string".
But I understood that will not work with datastore generated keys since the
parent needs to be persisted in order to get a key. Apologies for the naive
question :).
Manny

On Fri, Feb 12, 2010 at 1:41 AM, Ikai L (Google)  wrote:

> Are both the parent and child persisted at the same time? If so, you can
> add the child object as a child (not the Key) of the Parent object and call
> makePersistent on the Parent.
>
> On Thu, Feb 4, 2010 at 1:28 AM, Manny S  wrote:
>
>> I am missing something simple here but can anyone point me to how I can
>> set the child key before making the parent data persistent...(in a
>> unidirectional one to one relationship)
>>
>> I create the parent data and the child data
>>
>> parentdata pdata = new parentdata('x','y', 'z');
>> pdata.setKey(null);
>> childdata child = new childdata('A');
>> pdata.setChild(child);
>>
>> Now, I would like to set the child key as parent key + mystring
>>
>> When I try,
>> String strparentKey = KeyFactory.keyToString(pdata.getKey());
>> String strchildKey = strparentKey + "details";
>> Key childKey = KeyFactory.stringToKey(strchildKey);
>>
>> it gives me an error as the parent data does not have a key yet (cause is
>> null)
>>
>> In this case the key of the parent is generated only when I persist. But I
>> need to set the child key before I make it persistent. My application cannot
>> generate an unique app id and I rely on the datastore to do it. As far as I
>> can tell the KeyFactory.Builder does not have an option to generate unique
>> keys and relies on the app to provide it and so I cant use that either.
>>
>> Any help would be appreciated...
>>
>> Manny
>>
>> --
>> 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
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>> 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
> http://googleappengine.blogspot.com | http://twitter.com/app_engine
>
> --
> 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Setting the key of a child entity

2010-02-17 Thread Ikai L (Google)
There should be with KeyFactory's builder, but you may not want to go there:

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

On Sun, Feb 14, 2010 at 10:16 PM, Manny S  wrote:

> Thanks Ikai,
> I am doing it the way you described and it does work. Just wanted to know
> if there is a way to set the child key explicitly as parent + "const
> string". But I understood that will not work with datastore generated keys
> since the parent needs to be persisted in order to get a key. Apologies for
> the naive question :).
> Manny
>
> On Fri, Feb 12, 2010 at 1:41 AM, Ikai L (Google) wrote:
>
>> Are both the parent and child persisted at the same time? If so, you can
>> add the child object as a child (not the Key) of the Parent object and call
>> makePersistent on the Parent.
>>
>> On Thu, Feb 4, 2010 at 1:28 AM, Manny S  wrote:
>>
>>> I am missing something simple here but can anyone point me to how I can
>>> set the child key before making the parent data persistent...(in a
>>> unidirectional one to one relationship)
>>>
>>> I create the parent data and the child data
>>>
>>> parentdata pdata = new parentdata('x','y', 'z');
>>> pdata.setKey(null);
>>> childdata child = new childdata('A');
>>> pdata.setChild(child);
>>>
>>> Now, I would like to set the child key as parent key + mystring
>>>
>>> When I try,
>>> String strparentKey = KeyFactory.keyToString(pdata.getKey());
>>> String strchildKey = strparentKey + "details";
>>> Key childKey = KeyFactory.stringToKey(strchildKey);
>>>
>>> it gives me an error as the parent data does not have a key yet (cause is
>>> null)
>>>
>>> In this case the key of the parent is generated only when I persist. But
>>> I need to set the child key before I make it persistent. My application
>>> cannot generate an unique app id and I rely on the datastore to do it. As
>>> far as I can tell the KeyFactory.Builder does not have an option to generate
>>> unique keys and relies on the app to provide it and so I cant use that
>>> either.
>>>
>>> Any help would be appreciated...
>>>
>>> Manny
>>>
>>> --
>>> 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
>>> google-appengine-j...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> google-appengine-java+unsubscr...@googlegroups.com
>>> .
>>> 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
>> http://googleappengine.blogspot.com | http://twitter.com/app_engine
>>
>> --
>> 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
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>
>  --
> 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> 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
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Setting the key of a child entity

2010-02-18 Thread Manny S
Got it. Thanks again Ikai.
Manny

On Thu, Feb 18, 2010 at 12:16 AM, Ikai L (Google)  wrote:

> There should be with KeyFactory's builder, but you may not want to go
> there:
>
>
> http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html
>
>
> On Sun, Feb 14, 2010 at 10:16 PM, Manny S  wrote:
>
>> Thanks Ikai,
>> I am doing it the way you described and it does work. Just wanted to know
>> if there is a way to set the child key explicitly as parent + "const
>> string". But I understood that will not work with datastore generated keys
>> since the parent needs to be persisted in order to get a key. Apologies for
>> the naive question :).
>> Manny
>>
>> On Fri, Feb 12, 2010 at 1:41 AM, Ikai L (Google) wrote:
>>
>>> Are both the parent and child persisted at the same time? If so, you can
>>> add the child object as a child (not the Key) of the Parent object and call
>>> makePersistent on the Parent.
>>>
>>> On Thu, Feb 4, 2010 at 1:28 AM, Manny S  wrote:
>>>
 I am missing something simple here but can anyone point me to how I can
 set the child key before making the parent data persistent...(in a
 unidirectional one to one relationship)

 I create the parent data and the child data

 parentdata pdata = new parentdata('x','y', 'z');
 pdata.setKey(null);
 childdata child = new childdata('A');
 pdata.setChild(child);

 Now, I would like to set the child key as parent key + mystring

 When I try,
 String strparentKey = KeyFactory.keyToString(pdata.getKey());
 String strchildKey = strparentKey + "details";
 Key childKey = KeyFactory.stringToKey(strchildKey);

 it gives me an error as the parent data does not have a key yet (cause
 is null)

 In this case the key of the parent is generated only when I persist. But
 I need to set the child key before I make it persistent. My application
 cannot generate an unique app id and I rely on the datastore to do it. As
 far as I can tell the KeyFactory.Builder does not have an option to 
 generate
 unique keys and relies on the app to provide it and so I cant use that
 either.

 Any help would be appreciated...

 Manny

 --
 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
 google-appengine-j...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com
 .
 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
>>> http://googleappengine.blogspot.com | http://twitter.com/app_engine
>>>
>>> --
>>> 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
>>> google-appengine-j...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> google-appengine-java+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>
>>
>>  --
>> 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
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>> 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
> http://googleappengine.blogspot.com | http://twitter.com/app_engine
>
> --
> 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.