Hello,

The following scenario was giving me problems:

@PersistenceCapable
class Store {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;

  @Persistent
  User admin;

  @Persistent
  List<User> otherUsers;
}

because User appears twice within Store, so the framework was not letting
me do it.
My workaround was to define a new class with the following:

@PersistenceCapable
class Store {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;

  @Persistent
  AdminUser admin;

  @Persistent
  List<RegularUser> otherUsers;
}

but the problem is that I have functions that take User instances as
arguments and that
return User instances and I would like to not have to write separate
functions for RegularUser
and AdminUser.

So, I was wondering, if in addition to the above I were to add the
following:

@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class User {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
}

@PersistenceCapable
public class AdminUser extends User {

}

@PersistenceCapable
public class RegularUser extends User {

}

would this work? Note that with this scheme I will never persist references
to the abstract User type which will just be used in the arguments and
return
values of functions in my code for convenience. From what I gather on this
page
http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html
with this scheme I would only run into trouble if I were to call
pm.makePersistent(user)
where user is defined as User user; . I would not run into trouble if I
call pm.makePersistent(store)
because the calss store does not reference abstract class User. Am I
correct in making this assumption?

I am going to try it out.

Please let me know if you foresee any problems with this scheme.

Regards,

JG

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

Reply via email to