You cannot create a data model in JDO-GAE that is agnostic of its environment.
Twig allows your domains classes to use any key type you want or even none at all. class Parent { String name; @Entity(relation=child) Child child; } class Child { String name; } This will be correctly stored without any extra configuration http://code.google.com/p/twig-persist/ Its an option if your time is worth more than the small degree of portability you gain using a standard. On Jan 15, 9:24 pm, 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. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.