当最后一个孩子被移除时,JPA @ManyToOne会自动移除父母 [英] JPA @ManyToOne automatically remove parent when last child is removed

查看:87
本文介绍了当最后一个孩子被移除时,JPA @ManyToOne会自动移除父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @ManyToOne()
我有一个从孩子到父母的单向映射,像这样:@ManyToOne @JoinColumn(name =PARENT_ID)
私人ParentEntity父;

我有可能删除父母,当最后一个孩子被删除而没有从ParentEntity引用ChildEntities?没有任何注解我试过似乎工作。

解决方案

AFAIK没有方法从jpa做到这一点。
但是,您可以使用删除方法检查服务中的子实体数量,如果是最后一次,则可以删除父级。


I have an unidirectional mapping from child to parent by @ManyToOne like this:

@ManyToOne()
@JoinColumn(name = "PARENT_ID")
private ParentEntity parent;

I it possible to remove parent, when last child is removed without having reference from ParentEntity to ChildEntities? None of the annotations I tried seems to be working.

解决方案

AFAIK there is no method from jpa to do this. But you can check the number of child entitys in your service in the deletion method and than delete parent if it was the last.

这篇关于当最后一个孩子被移除时,JPA @ManyToOne会自动移除父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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