我正在使用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);"
}
}
This page提出了这样的建议:
// 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);
}
}
但我想更新整个嵌入式字段,而不是逐个更新每个子字段。我怎样才能做到这一点?谢谢!