问题
I have two relations in my class:
@OneToOne(mappedBy = "poi", cascade = { CascadeType.ALL })
@CascadeOnDelete
protected PoiDescription description;
@OneToMany(mappedBy = "poi", cascade = { CascadeType.ALL })
@CascadeOnDelete
protected List<PoiAdditional> additionals = new ArrayList<>();
In my generated DDL (for postgres) I becomes:
ALTER TABLE POI_DESCRIPTION ADD CONSTRAINT FK_POI_DESCRIPTION_POI_ID FOREIGN KEY (POI_ID) REFERENCES POI (ID)
ALTER TABLE POI_ADDITIONAL ADD CONSTRAINT FK_POI_ADDITIONAL_POI_ID FOREIGN KEY (POI_ID) REFERENCES POI (ID) ON DELETE CASCADE
Why the relation @OneToMany has the statement "ON DELETE CASCADE" and the relation @OneToOne has not?
Thanks in advance
回答1:
The current DDL generation code in EclipseLink seems to be check for the @CascadeOnDelete on the @OneToOne source, not the mappedBy. But I think you are correct, it should be checking the mapping using the mappedBy.
Please log a bug.
As a workaround you should be able to add it to both sides.
来源:https://stackoverflow.com/questions/15274428/eclipselink-cascadeondelete-doesnt-work-on-onetoone-relations