休眠中的@Fetch注释是什么? [英] What is @Fetch annotation in hibernate?

查看:134
本文介绍了休眠中的@Fetch注释是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@Fetch(FetchMode.SUBSELECT)
@JoinColumn(name = "ORU_OAUTH_ID", nullable = false)
@OrderBy("ORU_ORDER ")
private List<RedirectedURLs> acceptedReturnUrls;

  1. 在这段代码中,我想了解@Fetch(FetchMode.SUBSELECT)的作用?
  2. orphanRemoval和CascadeType.DELETE有什么区别?

推荐答案

  1. 如果这 链接 可以帮助你.
  1. If this link can help you.
  1. 对于CascadingType.DELETE和orphanRemoval

级联删除

使用CascadeType.REMOVE(或CascadeType.ALL, (其中包括REMOVE)表示删除操作应为 自动级联到该对象所引用的实体对象 字段(集合可以引用多个实体对象 字段):

Marking a reference field with CascadeType.REMOVE (or CascadeType.ALL, which includes REMOVE) indicates that remove operations should be cascaded automatically to entity objects that are referenced by that field (multiple entity objects can be referenced by a collection field):

@Entity
class Employee {
     :
    @OneToOne(cascade=CascadeType.REMOVE)
    private Address address;
     :
}

移除孤儿

JPA 2支持附加的和更积极的删除级联模式,可以使用以下命令指定orphanRemoval元素: @OneToOne和@OneToMany批注:

JPA 2 supports an additional and more aggressive remove cascading mode which can be specified using the orphanRemoval element of the @OneToOne and @OneToMany annotations:

@Entity
class Employee {
     :
    @OneToOne(orphanRemoval=true)
    private Address address;
     :
}

差异:-

两个设置之间的区别在于对断开关系的响应.例如,当设置 地址字段设置为null或另一个Address对象.

The difference between the two settings is in the response to disconnecting a relationship. For example, such as when setting the address field to null or to another Address object.

  • 如果指定了orphanRemoval = true,则会自动删除断开连接的Address实例.这对于清理很有用 没有一个不应该存在的相关对象(例如地址) 来自所有者对象(例如员工)的引用.

  • If orphanRemoval=true is specified the disconnected Address instance is automatically removed. This is useful for cleaning up dependent objects (e.g. Address) that should not exist without a reference from an owner object (e.g. Employee).

如果仅指定了cascade = CascadeType.REMOVE,则不会执行任何自动操作,因为断开关系不会被删除 操作.

If only cascade=CascadeType.REMOVE is specified no automatic action is taken since disconnecting a relationship is not a remove operation.

(级联删除和删除是同义词)

(Cascading Remove and Delete are synonyme)

此处.

这篇关于休眠中的@Fetch注释是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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