Eclipselink - @CascadeOnDelete doesn't work on @OneToOne relations

时光总嘲笑我的痴心妄想 提交于 2021-01-27 18:05:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!