架构:1个用户有1个GeneralData,没有用户
,GeneralData不能存在@PersistenceCapable
public class User implements Serializable{
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent
private String key;
@Persistent(defaultFetchGroup = "true")
@Element(dependent = "true")
private GeneralData data;
public void setKey(String key) {
this.key = key;
}
public String getKey() {
return key;
}
public void setData(GeneralData data) {
this.data = data;
}
public GeneralData getData() {
return data;
}
}
@PersistenceCapable
public class GeneralData implements Serializable{
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key;
@Persistent
private String name;
@Persistent(mappedBy = "data")
private User user;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setKey(Long key) {
this.key = key;
}
public Long getKey() {
return key;
}
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
}
我有2个问题,我做得对吗?
1)(用户和GeneralData之间的模式)
2)(添加实例到谷歌数据存储)
PersistenceManager pm = PMF.get().getPersistenceManager();
User onUser = new User();
GeneralData gd = new GeneralData();
gd.setName(usrname);
onUser.setKey(usrname);
onUser.setData(gd);
try {
pm.makePersistent(onUser);
} finally {
pm.close();
}