Deleting entity fails when field is mandatory

I have a table of Modules. One of the fields is typeModule which is a many-to-one relationship to the TypeModules table. Within Modules, I have set onDelete to unlink as I don’t want the deletion of a module to delete a typeModule.

Within Modules, when the typeModule relationship is not marked ‘Mandatory’, I can delete the module with no problem.
Within Modules, when the typeModule relationship is marked ‘Mandatory’, I can’t delete it with the error:
SQLIntegrityConstraintViolationException: integrity constraint violation: NOT NULL check constraint; SYS_CT_13508 table: MODULES column: TYPE_MODULE_ID

From the error message, it’s seems that the typeModule ID is null and thus causing the error. However, in my views (standard browse / edit), I am loading TYPE_MODULE_ID. I can see that it has loaded this attribute and is non null as I have made it a column and it shows on the screen.

Any advice on troubleshooting?

Hi,

Please provide the source code of these two entities for better understanding of your case.

Based on your description, you’ve probably used @OnDelete or @OnDeleteInverse annotation in the case where it should not be used.

I have set onDelete to unlink as I don’t want the deletion of a module to delete a typeModule.

By default (when no OnDelete / OnDeleteInverse annotations present) deletion of “Many” side of a ManyToOne relation will not lead to deleting “One” side.

Thanks @AlexBudarov. Removing OnDelete -> Unlink fixed the issue.