我正在相同类型的实体之间实现友谊功能Profile.此实体类型是root(非父)实体.一个Profile有一个Set<Ref<Profile>>名为的字段friends,它是getter getFriends().
这里的代码:
public boolean makeFriends(final Profile profile1, final Profile profile2) {
final Ref<Profile> profileRef1 = Ref.create(profile1);
final Ref<Profile> profileRef2 = Ref.create(profile2);
boolean result = false;
// test to avoid useless transaction
if (!profile1.getFriends().contains(profileRef2) && !profile2.getFriends().contains(profileRef1)) {
// add to friends (Set<Ref<Profile>>) the Ref of each other
result = ofy().transact(new Work<Boolean>() {
@Override
public Boolean run() {
profile1.getFriends().add(profileRef2);
profile2.getFriends().add(profileRef1);
ofy().save().entities(profile1, profile2).now();
return true;
}
});
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这段代码给了我一个:
java.lang.IllegalArgumentException: cross-group transaction …Run Code Online (Sandbox Code Playgroud)