JPA not generating “on delete set null” FK restrictions

前端 未结 5 585
[愿得一人]
[愿得一人] 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:39

    Are you sure with your @OneToOne? It seems to me that you'd rather use @ManyToOne (as a status can be affected to several alarms):

    @Entity
    public class Alarm {
        ...
    
        @ManyToOne(cascade=CascadeType.ALL)
        @JoinColumn(name="idStatus", nullable=true)
        private Status status;
    
        ...
    }
    

提交回复
热议问题