Hi Carl, You can use a string-encoded key on the child object to avoid a dependency on proprietary google classes. More info here: http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
(search for Key as Encoded String) Hope this helps, Max On Fri, Jan 15, 2010 at 6:24 AM, Carl Ballantyne <carlballant...@gmail.com>wrote: > Hi All, > > I have two classes, a Parent and a Child. (See below for code) The > Parent class contains a reference to a Child instance. However when I > try and save a Parent instance I get the following error: Cannot have > a java.lang.Long primary key and be a child object. > > The error is clear enough and upon searching around I have found the > solution is to convert the primary key of my Child class to Key. > However this just does not sit well with me that I have to modify my > domain classes with proprietary google classes to suit the datastore. > Is there no other way to do this without resorting to custom APIs at > the domain level? Or is this a limitation of JDO and I need to do a > bit more research? > > Cheers, > Carl. > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > public class Parent { > > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Long id; > @Persistent > private String name; > > @Persistent > private Child child; > > public Long getId() { > return id; > } > public void setId(Long id) { > this.id = id; > } > public String getName() { > return name; > } > public void setName(String name) { > this.name = name; > } > public Child getChild() { > return child; > } > public void setChild(Child child) { > this.child = child; > } > > > } > > > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > public class Child { > > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Long id; > @Persistent > private String name; > > > public Long getId() { > return id; > } > public void setId(Long id) { > this.id = id; > } > public String getName() { > return name; > } > public void setName(String name) { > this.name = name; > } > > } > > > -- > 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. > > > >--
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.