I have a table relationship defined as shown below, and I'm trying to cascade persistence and remove from Entity2 (Table 2). The recorder deletion tool from table2 should delete the entry in table3 and save the data in table2, saving the corresponding data in table 3.
oneToMany oneToMany
Table 1 (Entity1) (parent) --------> Table2 (Entity2) (Child in table1) ---------> Table3 (Child in table2) (Entity3)
oneToMany oneToMany
Table 1 (parent) --------> Table4 (Entity4) (Child in table1) ---------> Table5 (Child in table4) (Entity5)
Table 1 is the common parent for table 2 and table 4
Description of the problem:
1) CascadeType.REMOVE Entity1 {CascadeType.PERSIST, CascadeType.REMOVE} (Entity2 Entity4), 2 2 Entity3 ( 3), 1 (2 4), cascade.persist Entity1
2) {CascadeType.PERSIST, CascadeType.REMOVE} Entity1 {CascadeType.PERSIST, CascadeType.REMOVE} (Entity2 Entity4), 2 Entity3 (table3), 2 , Entity3 (3), ..... ( , , )
, .... CascadeType.PERSIST Entity1 ( 1) 2?
:
1 {
....
@OneToMany(cascade={CascadeType.PERSIST,CascadeType.REMOVE,mappedBy=....})
public Set<Table2> getTable2() {
return table2;
}
}
Table2 {
....
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(....)
public Table1 getTable1() {
return table1
}
@OneToMany(cascade={CascadeType.PERSIST,CascadeType.REMOVE,mappedBy=....})
public Set<Table3> getTable3() {
return table3;
}
}
3 {
....
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(....)
public Table2 getTable2() {
return table2;
}
}