Hibernate Criteria:inheritence:获取只有根类实体的列表

时间:2010-07-15 12:53:15

标签: java hibernate

假设我有:

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

如何选择仅保存为父级的实例,而不是选择子级。

谢谢

1 个答案:

答案 0 :(得分:2)

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

  

特殊属性class在多态持久性的情况下访问实例的鉴别器值。嵌入在where子句中的Java类名将被转换为其鉴别器值。

from Cat cat where cat.class = DomesticCat

因此,我相信您可以使用HQL约束... where class=Parent过滤掉Child的实例。