Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Spring数据Jpa保存对方实体时集合未更新_Spring_Jpa_Spring Data Jpa_Spring Data_Persistence - Fatal编程技术网

使用Spring数据Jpa保存对方实体时集合未更新

使用Spring数据Jpa保存对方实体时集合未更新,spring,jpa,spring-data-jpa,spring-data,persistence,Spring,Jpa,Spring Data Jpa,Spring Data,Persistence,我有两个实体处于一对多关系中: 母公司: @OneToMany(mappedBy = "parent") public List<Child> getChildren() 考虑以下代码(内部事务): Child-Child=childRepository.findById(id).get(); Parent-Parent=child.getParent(); setParent(null); childRepository.saveAndFlush(child); List chi

我有两个实体处于一对多关系中:

母公司:

@OneToMany(mappedBy = "parent")
public List<Child> getChildren()
考虑以下代码(内部事务):

Child-Child=childRepository.findById(id).get();
Parent-Parent=child.getParent();
setParent(null);
childRepository.saveAndFlush(child);
List children=parent.getChildren();
在这种情况下,“子”列表将仍然包含子实体,尽管它已被删除。我尝试刷新存储库,保存父实体,甚至从parentRepository获取一个新实体,但这些都不起作用

为什么保存时未更新子列表?如何确保集合是最新的,而不显式删除实体(我希望对集合中的实体进行进一步操作)

@ManyToOne
@JoinColumn(name = "PARENT_ID")
public Parent getParent()
Child child = childRepository.findById(id).get();
Parent parent = child.getParent();
child.setParent(null);
childRepository.saveAndFlush(child);
List<Child> children = parent.getChildren();