The ID for the owned child User instances has to be a Key or String type because the it contains both the reference to the parent(s) and the unique id of the object. A Long alone will not contain enough information to navigate the object model to it. I usually stick with String ids for all my types.
You can create/encode/decode Keys easily using the KeyFactory. On Mon, Oct 11, 2010 at 8:03 PM, Rick Curtis <[email protected]> wrote: > Hello all! I am new to GAE and have a pretty simple domain model that I'm > trying to persist. I am creating an Event(with a generated ID) and a > User(with a pre-defined ID) which is hosting the event. This is a one to one > relationship owned by the Event(@See below for code snippets). > > Upon commiting the transaction, I'm getting an exception which states > "Error in meta-data for User._id: Cannot have a java.lang.Long primary key > and be a child object (owning field is Event._host)." I did some searching > and came across this[1] post which suggested that I need to change my key > from a java.lang.Long to a com.google.appengine.api.datastore.Key. > > Since "The App Engine Java SDK includes an implementation of JPA 1.0 for > the App Engine datastore"[2]... I don't really need to use these internal > GAE classes to describe this mapping do I? Maybe I'm being a bit naive here, > but I have a hard time believing that this requirement/limitation is due to > the underlying database not being a relational database. > > Hopefully someone can shed some light on my findings. > > Thanks, > Rick > > @Entity > public class Event { > @Id > @GeneratedValue(strategy=GenerationType.IDENTITY) > Long _id; > > @OneToOne > User _host; > ... > } > > > @Entity > public class User { > @Id > Long _id; > ... > } > > [1] http://code.google.com/p/datanucleus-appengine/issues/detail?id=26 > [2]http://code.google.com/appengine/docs/java/datastore/usingjpa.html > > -- > 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. > -- 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.
