Answer the question
In order to leave comments, you need to log in
How to properly cascade remove child elements in hibernate?
I have a Device entity, with a OneToMany relationship to a Sensor entity. I need to make sure that when deleting a Device, all Sensors associated with it are deleted. Now the links are described as follows:
@OneToMany(mappedBy = "device", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Sensor> sensors;
@JoinColumn(name = "device_id")
@ManyToOne(fetch = FetchType.LAZY)
private Device device;
ERROR: ОШИБКА: UPDATE или DELETE в таблице "devices" нарушает ограничение внешнего ключа "fk834yqd4p6g9s2b6ufnba8bxrs" таблицы "sensors"
DETAIL: На ключ (id)=(18) всё ещё есть ссылки в таблице "sensors".
SQL state: 23503
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question