JPA not generating “on delete set null” FK restrictions

前端 未结 5 588
[愿得一人]
[愿得一人] 2021-01-04 19:11

I have two related clases JPA-annotated. Alarm and Status. One Alarm can have one Status.

What I need is to be able to delete one Status and \"propagate\" a null v

5条回答
  •  鱼传尺愫
    2021-01-04 19:48

    Just add that using the Hibernate annotation:

    @OnDelete(action=OnDeleteAction.CASCADE)
    

    generates the foreign key as : "ON UPDATE NO ACTION ON DELETE CASCADE;"

    But there is no action=OnDeleteAction.SET_NULL

    Moreover, I don't like to tie my code to Hibernate if possible (but I can live with it if it works).

    This thread discusses it. I can't believe there is not an easy method in JPA (or Hibernate extensions) to generate the foreign key.

提交回复
热议问题