Hi all,
in my projects data model some Type Hierarchies are mapped using a Descriminator Column on an abstract base Type. Sometimes Types have references to abstract base Types but I have to do queries on specialized Attributes. Currently I´m using Sub-Queries e.g.
Code:
@Entity
@DiscriminatorColumn(length = 2)
class Base{
String value;
...
}
@Entity
@DiscriminatorValue("A")
class A extends Base{
...
}
@Entity
@DiscriminatorValue("B")
class B extends Base{
String anotherValue;
...
}
@Entity
class X {
private Base base;
...
}
class SomeService{
void service(){
/*
find all X where X#base instanceof B and ((B) base)#anotherValue = "Hello World!";
*/
Select x from X x where x.base in (Select b from B b and a.anotherValue="Hello World!")
}
}
I don´t like this sub-query (last but not least because of potential performance risks). My questions are: Is there another way to express that with JPQL? Is there a way to build this query using the Criteria API?
Thanks all.