假设我有:
@Inheritance(strategy = InheritanceType.JOINED)
public class Child extends Parent{
}
如何选择仅保存为父级的实例,而不是选择子级。
谢谢
答案 0 :(得分:2)
查看section 14.9 of the Hibernate documentation的底部:
特殊属性
class
在多态持久性的情况下访问实例的鉴别器值。嵌入在where子句中的Java类名将被转换为其鉴别器值。
from Cat cat where cat.class = DomesticCat
因此,我相信您可以使用HQL约束... where class=Parent
过滤掉Child
的实例。