That's correct. First - you should read our documentation about entity
groups. The reason you can't update parents is because the actual key of the
object embeds parent information. For instance, a category key may look like
this:

Category(Mammal)

Subcategories may have keys that decode to the following:

Category(Mammal):SubCategory(Bipedal):SubCategory(Simian)

If you create the categories "Bipedal" and "Simian" first, you'll have an
entity with the key:

SubCategory(Bipedal):SubCategory(Simian)

You can't change a key once an object is persisted. It needs to become a new
entity entirely, as keys are immutable. Thus - to place these under the
Category with "Mammal" as a key, you'll have to create a new object and
destroy the old object.

As a design pattern, generally speaking you should try to create parent
objects first, as you could have an issue where deleting an old category
fails after creating a new one, or vice versa. Since you won't be able to
create a transaction around these objects (they won't be in the same entity
group), you'll end up with either data loss or an orphaned, duplicate
category. This will be rare, though, so it may not make sense to code to
avoid this.

On Tue, Apr 13, 2010 at 4:54 AM, gemma <gemmasilv...@googlemail.com> wrote:

> Hello!
>
> I'm currently writing an app where the datamodel has a set of Category
> objects with SubCategory children which represents a classification
> tree.  I've now gotten to the stage where I'm attempting to apply
> these Category and SubCategory objects as attributes of an Item
> object, but am getting an error that says that once an object has been
> persisted, you can't create or modify its parent.
>
> That's cool, I'm happy to change my Item class so that instead of
> having persistent Category and SubCategory items directly as
> attributes they have the string repesentation of the Category and
> SubCategory keys - but is this an acceptable design approach?
>
> Any thoughts would be greatly appreciated.
>
> Thanks!
> Gemma
>
> --
> 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<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Relations, Google App Engine
Twitter: http://twitter.com/ikai
Delicious: http://delicious.com/ikailan

----------------
Google App Engine links:
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 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.

Reply via email to