我正在使用 Morphia 0.99,我正在尝试更新实体中的嵌入字段,但我不知道如何。
// User entity
@Entity(value = "users", noClassnameStored = true)
public class User
{
@Id
private String id;
@Embedded
private UserConfig userConfig;
}
// User DAO
public class UserDao extends BasicDAO <User, ObjectId> implements IUserDao
{
@Override
public void setConfig (String userId, UserConfig config)
{
User user = get (new ObjectId (userId));
user.setNotificationsTypes (notitypes);
"this.update(user);"
}
}
这个页面提出了这样的建议:
// User DAO
public class UserDao extends BasicDAO <User, ObjectId> implements IUserDao
{
@Override
public void setConfig (String userId, UserConfig config)
{
Query <User> query = ds.createQuery (User.class).field (idString).equal (userId);
UpdateOperations <User> ops = ds.createUpdateOperations (User.class).set ("userConfig.someField", "Some Value");
ds.update (updateQuery, ops);
}
}
但我想更新整个嵌入字段,而不是一个一个地更新每个子字段。我怎样才能做到这一点?谢谢!