Hi
I'm dealing with an existing Oracle DB which has two tables looking like : PARENT ( ID, NAME, .... ) CHILD ( ID, PARENT_ID, NAME, ... )
CHILD.PARENT_ID column has a Foreign Key on PARENT.ID colum with the "On Delete Option" which allows to delete directly entries in PARENT without having to delete explicitely linked entries in CHILD table - Oracle will do it automatically
(the creating scripts looks like :
alter table CHILD add constraint FK_PARENT_ID foreign key (PARENT_ID) references PARENT_ID (ID) on delete CASCADE
)
)
On Java side, I've got so far something like:
public class ChildDTO implements Serializable { ... @ManyToOne @JoinColumn(name = "parent_id") @MapsId("id") private ParentDTO parent;
... }
public class ParentDTO implements Serializable { ... @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) private Set<ChildDTO> childs;
... }
When deleting an ParentDTO objects, ChildDTO objects related to the ParentDTO are deleted to. But I can also observe on Oracle side that Hibernate sends a DELETE requests on the table CHILD, though it's not necessary since the "On Delete Cascade" option of my FK make Oracle delete CHILD whenever it's PARENT_ID does not exists anymore in the PARENT table. So I would like to know the correct option to set , so as Hibernate wont send the DELETE requests on CHILD table anymore, while still handling correctly the ParentDTO <> ChildDTO relationship.
So far I tried this other setting with no success : @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = false) (apparently not correct on Java side) and @OneToMany(mappedBy = "parent", cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH, CascadeType.PERSIST}, orphanRemoval = true) (didn't seem to change anything)
Thanks in advance!
Last edited by Astrodoudou on Wed Jul 22, 2015 4:42 am, edited 1 time in total.
|