Search code examples
javaeclipselink

eclipselink condition on class type in ReportQuery


Assume I have two entities ChildClassA e ChildClassB that inherits from class MySuperClass:

@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 
{
    ...
}

I also have another class OtherClass with a property myclass of type MySuperClass:

@Entity
public class OtherClass
{   
    ...

    @ManyToOne
    private MySuperClass myclass;
    ...
}

I want to make a query on the entity OtherClass, in the where clause i need a condition like instanceof to apply on the property myclass. Something like this:

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);

Is there a way to do ebQuery.get("mySuperClass").instanceOf(ChildClassA.class) ?


Solution

  • You need to use type():

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