Hibernate 具有一对多的实体在更新时不添加新的子项

Hibernate 具有一对多的实体在更新时不添加新的子项,hibernate,spring-boot,spring-data-jpa,one-to-many,Hibernate,Spring Boot,Spring Data Jpa,One To Many,我有以下实体 @Entity @Audited public class Parent { @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @Audited(modifiedColumnName = "children_modified") private List<Children> children; ... } reposit

我有以下实体

@Entity
@Audited
public class Parent {
    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Audited(modifiedColumnName = "children_modified")
    private List<Children> children;
    ...
}
repository方法仅调用parentRepository.save(SpringDataJPA)

然后,在服务调用之后,我可以看到父实体有一个子实体,该实体有一个id

然后,稍后,我添加一个新的子项,相同的过程:

parent.addChild(new Child(parent, "child2"))
parentService.updateParent(parent)

但是,第二个孩子没有设置id。你知道我做错了什么吗?

你能显示parent.addChild?public void addChild(Child-Child){if(this.children==null){this.children=new arrararylist();}this.children.add(Child);}你设置了申请者字段吗?你好@SimonMartinelli,我更新了这个问题。是的,我设置了它,通过新的子对象(父对象,“child2”),save方法将返回保存的实体。是否使用此选项添加第二个子项?
parent.addChild(new Child(parent, "child2"))
parentService.updateParent(parent)