I have one scenario as following
Class A {
String id;
List<B> lstB;
}
Class B {
String id;
String name;
}
Class C extends B {
String location;
}
For above mapping here is my Hibernate mapping
<class name="A" table="A">
<id name="id" type="java.lang.String" column="ID" length="50">
<generator class="assigned" />
</id>
<set name="lstB" table="A_B" lazy="true">
<key column="A_ID" />
<many-to-many column="B_ID" class="B" />
</set>
</class>
<class name="B" table="B">
<id name="id" type="java.lang.String" column="ID" length="50">
<generator class="assigned" />
</id>
<property name="name">
<column name="NAME"/>
</property>
<discriminator column="DISCRIMINATOR" not-null="false" />
<subclass name="C" discriminator-value="C">
<property name="location">
<column name="LOCATION"/>
</property>
</subclass>
</class>
Now I want to retrieve List of B
and C
objects on the basis of following given parameters.
1) id given from A
.
2) Location from C
.
Now if result object is instance of B
then just add in list but if it is instance of C
then have to verify with Location name passed in where clause.
Can I achieve this using HQL? or I have to go with Criteria API? Can we check instance of object from HQL itself?