java - 如何在多对多关系中使用 hibernate 和 JPA 删除孤立实体?

标签 java sql hibernate jpa

我想在多对多关系上使用 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/

相关文章:

java - 在 MVC 中,与应用程序模型相反的 GUI 模型是什么?

java - 多个ListCell渲染器

Java无法从数组获取用户输入

mysql - 在 MySQL 中计算转化率

java - 来自数据库的 Hibernate 字段中的 transient

java - hibernate 状态下的 Postgresql 'select distinct on'

java - 从 ArrayList 中删除不起作用

mysql - 如何对重复的 mysql 数据进行非规范化?

c# - 这个特定的别名 SQL 列是否存在问题?

MongoDB到Java的集成