You might find it easier to use one of the datastore specific persistence interfaces like ObjectDatastore

You could then define a much cleaner data model like:

class Company
{
        Collection<Person> employees;
}

class Person
{
        @Child User user;  // could use @Embed instead
}

I've left out the super class with the key because normally keys are not needed with the ObjectDatastore... Twig manages those behind the scenes for you. Perhaps you could embed the user instead - would it normally be loaded at the same time as a Person?

More details http://groups.google.com/group/twig-persist

On 13 Apr 2010, at 23:01, korey_sed wrote:

I have three Classes (User, Person, Company) that are all subclasses
of BaseClass.

Company has a list of employees<Person>
Person may have a user<User>

@PersistenceCapable(detachable="true")
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class BaseObject {

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 Key id;
}

@PersistenceCapable(detachable="true")
public class Company  extends BaseObject {

 @Persistent(mappedBy = "employer")
 @Order(extensions = @Extension(vendorName="datanucleus", key="list-
ordering", value="lastName asc, firstName asc"))
 List<Person> employees;
}

@PersistenceCapable(detachable="true")
public class Person extends BaseObject {

 @Persistent
 Company employer;

//  @Persistent(mappedBy = "person")
//  User user;
}

@PersistenceCapable(detachable="true")
public class User extends BaseObject {
 @Persistent
 Person person;
}

Now I can create a company, persist it, then create a person, set its
employer, and persist it.  But I cannot create a user and set its
person.  GAE thinks that I am trying to make User the parent of
person, but it actually the other way around.
"Detected attempt to establish User(7) as the parent of Company(5)/
Person(6) but the entity identified by Company(5)/Person(6) is already
a child of Company(5)."

I had to comment out the User back reference in Person since with it,
GAE things that Person has more than one parent.  This is odd as well,
but I can live without it if i have to.  I am just trying to avoid
doing this with not-owned relationship between user and person.

what am i doing wrong? or is this just a bug?

Thanks.

--
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-java@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 .


--
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