开发者

Owned and Unowned relationship in JDO/GAE

开发者 https://www.devze.com 2023-04-01 05:01 出处:网络
I am trying to understand the concepts of owned and unowned relationships in JDO/GAE using the following model:

I am trying to understand the concepts of owned and unowned relationships in JDO/GAE using the following model:

Definition for EMPLOYEE

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

   @Persistent
   private String firstName;


   @Persistent
   private String lastName;

   @Persistent
   private User user;
}

Definition for USER

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

   @Persistent
   private String userName;

   @Persistent
   private String password;

   @Persistent
   private Key role;
}

Definition for ROLE

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

   @Persistent
   private String roleName;

   @Persistent
   private String status;
}

Each Employee has an User account and each user account is associated with a role.

The requirement is such that, when I list the employees, it should show the User.username as well as Role.rolename associated with that record.

I have the following questions related to this model:

  1. After going through GAE official documentation I assume that the relationship between Employee and User is owned and that of User and Role is unowned. Is my assumption correct?

  2. Does this model makes sense in GAE/JDO?

  3. How can I write a query to list the employees in the above mentioned requirement?

In addition to the official documentation I have also refer开发者_如何学Gored http://thoughts.inphina.com/2010/08/04/gae-unowned-relationships-preferred/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号