JPA's cascade = REMOVE and Hibernate's @OnDelete used together?

前端 未结 1 1403
遥遥无期
遥遥无期 2020-12-14 04:31

I have inherited a code base on which nearly all relations have the following annotations:

@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE          


        
相关标签:
1条回答
  • 2020-12-14 05:12

    Let's say you have a one-to-one directional relationship

    class House {
    
        @OneToOne
        Object door;
    
    }
    

    If you use CascadeType.REMOVE then deleting the house will also delete the door.

        @OneToOne(cascade=CascadeType.REMOVE)
        Object door;
    

    If you use @OnDelete then deleting the door will also delete the house.

        @OneToOne
        @OnDelete(action = OnDeleteAction.CASCADE)
        Object door;
    

    Read more here: http://www.ninthavenue.com.au/jpa-cascadetype-remove-vs-hibernate-ondelete

    0 讨论(0)
提交回复
热议问题