java - 如何在 Springboot 应用程序中使用 mongo jpa 处理基类更新?
问题描述
对 mongo 实体使用继承时,如何正确处理基类的更新?
基类:
@Document
public class User {
@Id
private String id;
@UniqueElements
protected String uid;
protected String photoUrl;
protected Address homeAddress;
protected Gender gender;
protected List<Kid> kids;
protected GeneralInfo generalInfo;
protected List<Address> addresses;
protected String instanceId;
public User() {
}
public User(User user) {
this.uid = user.getUid();
this.photoUrl = user.getPhotoUrl();
this.homeAddress = user.getHomeAddress();
this.gender = user.getGender();
this.kids = user.getKids();
this.generalInfo = user.getGeneralInfo();
this.addresses = user.getAddresses();
this.instanceId = user.getInstanceId();
}
}
孩子们:
@Document
public class Sitter extends User{
private int childCareExperienceYrs;
private AgeRange preferredKidsAgeRange;
private List<Skill> skills;
private String talents;
private LivingSpace livingSpace;
@JsonProperty
private boolean pets;
@JsonProperty
private boolean hasCar;
@JsonProperty(value = "available")
private boolean available;
}
@Document
public class Parent extends User{
}
从 User 继承的属性保存在子文档中。当我更新用户属性时,子表不会更新。
例如,更改用户地址时,“Sitter”文档仍将具有旧地址。
如何从基类进行任何更改以反映子类?
当基类更改时,这种情况是否需要对每个孩子进行更新查询?
解决方案
推荐阅读
- javascript - 在 expo react-native 应用程序中初始化 firebase phone auth
- python - 使用 Pillow 和/或 NumPy 进行快速像素操作
- unity3d - CG Shader 如何在不同比例的 3 种颜色之间进行插值?
- angular - 如何从数字中获取月份的名称?
- firebase - Firebase 反应原生加载问题
- python - 如何创建具有多个条件的正则表达式?
- c# - 使用NetworkStream c#后如何在Socket中保持连接
- google-cloud-platform - 有谁知道云运行是否支持 http/2 流而不支持 http1.1 流?
- python - 为什么 Python 只允许我使用一次打开的文件?
- python - Mongodb 4.2 使用聚合管道更新更快的方法来仅更新数组中的一个元素?