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
JPA合并更新关系图中的所有对象_Jpa_Ejb_One To Many_Cascade - Fatal编程技术网

JPA合并更新关系图中的所有对象

JPA合并更新关系图中的所有对象,jpa,ejb,one-to-many,cascade,Jpa,Ejb,One To Many,Cascade,我有一个实体,它与另一个实体有一对一的关系 @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(mappedBy = "entity1", cascade = CascadeType.ALL) private List<Entity2> entity2; 现在,我们有两个Entity1的实例。每个实例只有一个实体2的实例。我想将一个Entity1对象与Entity2一起更新,但如果使用 em.merge(Entity1)

我有一个实体,它与另一个实体有一对一的关系

@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "entity1", cascade = CascadeType.ALL)
private List<Entity2> entity2;
现在,我们有两个Entity1的实例。每个实例只有一个实体2的实例。我想将一个Entity1对象与Entity2一起更新,但如果使用

em.merge(Entity1)
它将触发两个update语句并更新两个Entity2。但我只想更新与此Entity1关联的Entity2


请告诉我,我这里缺少什么

可能是很晚才回复。但可能对其他人有用。 尝试使用
cascade.PERSIST
并手动处理子实体的更新/合并

em.merge(Entity1)