如何在多对多关系中使用hibernate和JPA删除孤立实体? [英] How do I delete orphan entities using hibernate and JPA on a many-to-many relationship?

查看:180
本文介绍了如何在多对多关系中使用hibernate和JPA删除孤立实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过多对多关系来删除使用hibernate和JPA的孤儿实体,但是我发现所有的属性都是这个属性。 org.hibernate.annotations.CascadeType.DELETE_ORPHAN(即@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN)),它只适用于一对多的关系。

I want to delete orphan entities using hibernate and JPA on a many-to-many relationship but all that I found was this attribute the attribute. org.hibernate.annotations.CascadeType.DELETE_ORPHAN ( i.e. @Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN) ), which works only for one-to-many relationships.

我想知道是否可以删除我的多对多关系中的孤儿。

I want to know if I can delete the orphan ones on my many-to-many relationship.

推荐答案

从书籍Pro JPA 2:

From the book "Pro JPA 2":


只有在源端有单基数的关系可以
启用孤儿删除,为什么orphanRemoval选项是在@OneToOne和@OneToMany关系注释中定义的
,而不是@ManyToOne或@ManyToMany注释中的

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.

这是一个无赖,但没有JPA自动孤儿删除ManyToMany。

It's a bummer, but there is no JPA automated orphan removal for ManyToMany.

这篇关于如何在多对多关系中使用hibernate和JPA删除孤立实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆