I’m working with Hibernate 5.2.18 and for performance improvement I have to use HQL request.
My issue is that I have a parent object like “Parent” which is containing many subclasses like: ChildA to ChildZ.
Property1 is only declare for ChildA and ChildB.
Property2 is only declare for ChildA.
What I want is to request like that:
“SELECT p FROM Parent WHERE property1 = ?1 OR property2 = ?2”
This previous request obviously not working so I wrote the following request which is working:
“SELECT p FROM Parent WHERE (p.class = ChildA AND (p.property1 = ?1 OR p.property2 = ?2)) (p.class = ChildB AND p.property1 = ?1”)
Is there a way to avoid testing cast ?
Maybe by changing my hibernate mapping ?