google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Need better error message for "Can't automatically generate Keys for embedded entities/No Cascading Saves" #122

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From Jeff:

Ok, I know what's going on.  Notice that this is going through an 
EntityReferenceTranslator, which means the culprit is a Key (actually 
an Entity reference) in a property of another entity. 

Somewhere you have a class that looks like this: 

@Entity 
class Foo { 
   ... (id, etc) 
   List<OPDSEntry> entries; 
} 

...and what you are doing is trying to save a Foo whose 'entries' 
contains an OPDSEntry without an id.  There is no cascading save in 
Objectify; entity references are treated just like Keys.  You're 
trying to store an incomplete key in the collection. 

There are two solutions to this: 

 1) Save the OPDSEntries first, before the Foo.  This will 
autogenerate the ids of the entries, and then the Foo save will work 
normally. 

 2) If you really want to save the Foo and entries all in one batch 
call, manually allocate the ids of the entries.  This isn't a bad 
strategy.  To be honest, I think automatic id generation is a 
generally poor idea.  It's usually best to generate ids outside of a 
transaction to get better idempotence. 

The error message for this case is really inadequate.  I can see this 
issue coming up again.  Would you file an issue about it? 

Thanks, 
Jeff 

Original issue reported on code.google.com by Palan...@gmail.com on 8 May 2012 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by lhori...@gmail.com on 8 May 2012 at 5:06

GoogleCodeExporter commented 9 years ago
This kind of entity reference has been disallowed for some time; instead we 
have Ref<?>. Closing this issue.

Original comment by lhori...@gmail.com on 14 Apr 2014 at 12:32