Reputation: 903
Below issue comes up when I delete Loan entity. Ran app with hibernate show-sql:true and found null, in a query build by hibernate.
Hibernate: update activity set loan_id=null where loan_id=?
2020-07-14 23:53:20.944 WARN 13820 --- [nio-6080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 19, SQLState: null
Followed this answer, 'Cascade.ALL' in entity class didnt help. Do I have option other than add lines to find and delete the child entities first, then attempt loan deletion.
ER diagram:
Git link in case needed.
Upvotes: 0
Views: 395
Reputation: 903
As parent entity is issued with deletion request, Hibernate takes the liberty of updating child entity's foreign key with null value, rendering the child, an orphan. As null constraint is applied on the foreign key column, db throws error.
Setting orphanRemoval=true is not working either.
To force hibernate to delete child object I followed the below answer. https://stackoverflow.com/a/17049049/7268798
Upvotes: 1