gpt4 book ai didi

hibernate - 什么是 hibernate 中的@Fetch 注释?

转载 作者:行者123 更新时间:2023-12-03 08:04:52 28 4
gpt4 key购买 nike

@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;
  • 在这段代码中,我想了解 @Fetch(FetchMode.SUBSELECT) 做什么?
  • orphanRemoval 和 CascadeType.DELETE 有什么区别?
  • 最佳答案

  • 如果这
    link
    能帮你。
  • 对于 CascadingType.DELETE 和 orphanRemoval

  • Cascading 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;
    :
    }

    Orphan Removal

    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;
    :
    }

    DIFFERENCE:-

    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.

    • 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).

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



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

    来自 here .

    关于hibernate - 什么是 hibernate 中的@Fetch 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43515949/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com