Using PostgreSQL, why doesn't Hibernate/JPA create cascade constraints?

后端 未结 2 501
一整个雨季
一整个雨季 2021-02-16 00:26

I have an entity Bar:

@OneToMany(cascade = CascadeType.ALL, mappedBy = \"bar\")
private Set fooSet;

And an entity

2条回答
  •  时光说笑
    2021-02-16 00:53

    Using

     cascade = CascadeType.ALL
    

    causes hibernate to traverse this relationship if you perform any operation. It doesn't influence generated DLL.

    If you want to delete all entities in fooSet add orphanRemoval attribute.

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "bar", orphanRemoval=true)
    

    Also using

    
    

    is good ONLY for development environment. Don't use it for production. (e.g. hibernate can't know how to change table schema if you for example rename a property/column wil create another column and maybe even drop the previous one).

提交回复
热议问题