我有以下实体:

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="orderType", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue(value="BASE")
@Table(name = "orders")
public class OrderEntity implements Serializable {
...


@Entity
@DiscriminatorValue(value="RECURRING")
public class RecurringOrderEntity extends OrderEntity{
...

我可以使用以下jpql找到所有子类(RecurringOrderEntity):
Query q = em.createQuery(
                "SELECT o from RecurringOrderEntity o where "
                + "o.cancellationDate is null "
                + "and o.maxOccurrences = o.occurrence");

仅查找不是RecurringOrderEntity实例的实体的JPQL语法是什么?

我正在使用Eclipselink 2.0.0作为JPA提供程序。

谢谢!

最佳答案



通过TYPE运算符使用实体类型表达式。这样的事情(不确定所需的确切查询,但您知道了):

SELECT o
FROM OrderEntity o
WHERE TYPE(o) <> RecurringOrderEntity
  AND o.cancellationDate is null
  AND o.maxOccurrences = o.occurrence

以下是JPA 2.0规范的相关部分:

10-06 02:24