DELETE_ORPHAN和DELETE有什么区别? [英] What is the difference between DELETE_ORPHAN and DELETE?

查看:165
本文介绍了DELETE_ORPHAN和DELETE有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

源代码:

  @OneToOne(fetch = FetchType.LAZY)
@Cascade({SAVE_UPDATE ,EVICT,DELETE})
@JoinColumn(name =A_ID,nullable = true)
private A a;

@OneToMany
@Cascade({SAVE_UPDATE,EVICT,DELETE,DELETE_ORPHAN})
@JoinColumn(name =B_ID)
private List< B> bList;

DELETE_ORPHAN和DELETE有什么不同?

解决方案

级联DELETE表示如果删除此实体,删除相关的实体或实体。



DELETE_ORPHAN表示如果从相关的一对多集合中删除一个实体,则不仅将其从当前实体中解除关联,而且将其删除。



房屋房间列表上的DELETE表示如果删除房屋,则删除所有房屋。 。

DELETE_ORPHAN在House上的房间列表上表示如果您从该集合中删除了一个房间,则完全删除它。没有它,房间仍然存在,但不会附加到任何东西上(因此孤儿)。

在UML和OO建模术语中,这基本上是组合和聚合。房子 - >房间关系是构图的一个例子。一个房间是众议院的一部分,并不是独立存在的。



聚合的一个例子是,例如,学生(孩子)的类(父)。删除班级和学生仍然存在(无疑在其他班级)。从班级中删除学生通常不意味着删除他或她。


Here is source code:

@OneToOne(fetch = FetchType.LAZY)
@Cascade({SAVE_UPDATE, EVICT, DELETE})
@JoinColumn(name = "A_ID", nullable = true)
private A a;

@OneToMany
@Cascade({SAVE_UPDATE, EVICT, DELETE, DELETE_ORPHAN})
@JoinColumn(name = "B_ID")
private List<B> bList;

What is the difference between DELETE_ORPHAN and DELETE ?

解决方案

Cascade DELETE means if this entity is deleted, delete the related entity or entities.

DELETE_ORPHAN means if an entity is removed from a related one-to-many collection, then not only disassociate it from the current entity, but delete it.

To give you an example, consider two entities: House and Room.

DELETE on the Room list on House means that if you delete the House then delete all it's Rooms.

DELETE_ORPHAN on the Room list on House means if you remove a Room from that collection, delete it entirely. Without it, the Room would still exist but not be attached to anything (hence "orphan").

In UML and OO modelling terms, this is basically the difference between composition and aggregation. The House->Room relationship is an example of composition. A Room is part of a House and doesn't exist independently.

An example of aggregation is, say, Class (parent) to Student (child). Delete the Class and the Student still exists (undoubtedly in other classes). Removing the Student from the Class doesn't typically mean deleting him or her.

这篇关于DELETE_ORPHAN和DELETE有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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