gpt4 book ai didi

java - ReportQuery 中类类型的 eclipselink 条件

转载 作者:行者123 更新时间:2023-12-01 11:47:51 25 4
gpt4 key购买 nike

假设我有两个继承自 MySuperClass 类的实体 ChildClassA 和 ChildClassB:

@Entity
@Table(name = "MY_TAB")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "MY_DISC")
public class MySuperClass
{
@Column
private String X;
@Column
private String Y;
...
}

@Entity
@DiscriminatorValue(value = "A")
public class ChildClassA extends MySuperClass
{
...
}

@Entity
@DiscriminatorValue(value = "B")
public class ChildClassB extends MySuperClass
{
...
}

我还有另一个类 OtherClass,其属性 myclass 类型为 MySuperClass:

@Entity
public class OtherClass
{
...

@ManyToOne
private MySuperClass myclass;
...
}

我想对实体OtherClass进行查询,在where子句中我需要像instanceof这样的条件来应用于属性myclass。像这样的事情:

ExpressionBuilder ebQuery = new ExpressionBuilder();
ReportQuery rQuery = new ReportQuery(OtherClass.class, ebQuery);

Expression exp = ebQuery.get("X").equal("my value x")
.and(ebQuery.get("Y").equal("my value y"))
.and(ebQuery.get("myClass").instanceOf(ChildClassA.class));

rQuery.setSelectionCriteria(exp);

ExecuteQuery(ebQuery);

有没有办法做到ebQuery.get("mySuperClass").instanceOf(ChildClassA.class)

最佳答案

您需要使用type():

ebQuery.get("myClass").type().equal(ChildClassA.class)

关于java - ReportQuery 中类类型的 eclipselink 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29015139/

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