我正在将 gwt 与 jdo datanucleus 一起使用。我有要求让孩子和父母在一起。但是当访问父母时我没有得到孩子。我的代码如下
我的家长班是
@PersistenceCapable(identityType = IdentityType.APPLICATION, table = "user")
public class User implements Serializable {
private static final long serialVersionUID = 2660867968471555842L;
@PrimaryKey
@Persistent
private String email;
@Persistent(defaultFetchGroup = "true",mappedBy="user")
private UserProfile profile;
public User() {}
public User(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public UserProfile getProfile() {
return profile;
}
public void setProfile(UserProfile profile) {
this.profile = profile;
}
}
我的孩子班是
@PersistenceCapable(identityType = IdentityType.APPLICATION,table = "user_profile")
public class UserProfile implements Serializable {
private static final long serialVersionUID = -6818036410894395030L;
@PrimaryKey
@Persistent(defaultFetchGroup="true")
private User user;
@Persistent
private String name;
public UserProfile() {}
public UserProfile(User user) {
this.user = user;
user.setProfile(this);
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我正在通过以下查询获取数据
PersistenceManager pm = PMF.get().getPersistenceManager();
User user=null;
try{
String userId ="abc@abc.com";
Query userQuery = pm.newQuery(User.class);
userQuery.setFilter("email == '" + userId + "'");
userQuery.setUnique(true);
user = (User) userQuery.execute();
} catch (Exception e) {
throw new IllegalAccessError("Failed to get the User..");
}finally{
pm.close();
}
但我在对象用户中得到 userprofile null。哪里有问题 ?如何将孩子与父母一起加载?