Can I add 'ON DELETE CASCADE' to tables managed by Hibernate?

后端 未结 6 1706
不知归路
不知归路 2021-01-04 00:14

I have some tables managed by Hibernate with various foreign key constraints. Cascade on delete is currently managed by Hibernate alone. For playing around with test data I

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 01:04

    You can safely use ON DELETE CASCADE as long as you do not have CascadeType.REMOVE or orphanRemoval enabled to prevent propagation of the entity removal event.

    Having @OnDelete(action = OnDeleteAction.CASCADE) on your relation will force Hibernate to generate ON DELETE CASCADE for related foreign keys. However your Dialect has to indicate that such relation are supported by returning true in supportsCascadeDelete method.

    Dialect.supportsCascadeDelete()

    OnDelete

提交回复
热议问题