gpt4 book ai didi

java - hibernate 条件 : inheritence: Get a list of only the root class entities

转载 作者:行者123 更新时间:2023-11-30 09:54:27 27 4
gpt4 key购买 nike

假设我有:

@Inheritance(strategy = InheritanceType.JOINED)
public class Child extends Parent{
}

我怎样才能只选择保存为父项而不是子项的实例。

谢谢

最佳答案

看看section 14.9 of the Hibernate documentation的底部:

The special property class accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value.

from Cat cat where cat.class = DomesticCat

所以我相信在您的情况下,您可以使用 HQL 约束 ... where class=Parent 来过滤掉 Child 的实例。

关于java - hibernate 条件 : inheritence: Get a list of only the root class entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3255652/

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