我不确定我是否以正确的方式使用 @Id 来客观化。现在我使用电子邮件地址作为@Id 字段。电子邮件字段将仅在服务器端设置 (OAuthService.getCurrentUser.getEmail)
第一个问题:这是个好主意吗?
例如,如果我创建一个具有 RegistrationTO 作为其父级的 Item-class,那么在我的 Item-class 中使用电子邮件地址作为 @Id 字段是否有意义,或者 Item-class 是否应该拥有它自己的、自动生成的 id 和指定关系的关键父级?
Objectify-Tutorial 建议避免使用@Parent - 所以,我认为也没有必要。我是对的?
这是我的注册地址:
public class RegistrationTO implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Size(min = 5, max = 20)
private String firstname;
@NotNull
@Size(min = 5, max = 20)
private String name;
@NotNull
@Size(min = 5, max = 20)
private String country;
@Id
@NotNull
@Size(min = 5, max = 20)
@Pattern(regexp = "\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\b")
private String email;
public RegistrationTO() {
}
public RegistrationTO(final String firstname, final String name, final String company) {
this.firstname = firstname;
this.name = name;
this.country = country;
email = "will be set on server (Oauth)";
}
public String getFirstname() {
return firstname;
}
public String getName() {
return name;
}
public String getCountry() {
return country;
}
public String getEmail() {
return email;
}
public void setEmail(final String email) {
this.email = email;
}
}
项目类示例:
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
Long id
//or
//@Id
//String email
Key<RegistrationTO> parent;
String itemno;
}
先感谢您!