我想在多对多关系上使用 hibernate 和 JPA 删除孤立实体,但我发现的只是属性 org.hibernate.annotations.CascadeType.DELETE_ORPHAN
,它仅适用于一对多关系。
我想知道我是否可以删除我的多对多关系中的孤儿。
最佳答案
来自“Pro JPA 2”一书:
Only relationships with single cardinality on the source side can enable orphan removal, which is why the orphanRemoval option is defined on the @OneToOne and @OneToMany relationship annotations, but on neither of the @ManyToOne or @ManyToMany annotations.
这很糟糕,但没有针对 ManyToMany 的 JPA 自动孤儿删除。
关于java - 如何在多对多关系中使用 hibernate 和 JPA 删除孤立实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3055407/