Suppose I have some classes, like this:
OpA extends Operation OpA1 extends OpA OpA2 extends OpA OpB extends Operation OpB1 extends OpB OpB2 extends OpB OpB3 extends OpB OpC extends Operation Operation | /-----------------------------\ / | \ OpA OpB OpC / | / | /------\ /-----------\ / \ / | \ OpA1 OpA2 OpB1 OpB2 OpB3 If I want to find some operations, I can do this:
session.createCriteria(Operation.class) .add(...) .add(...) .addOrder(...) .setFirstResult(...) .setMaxResults(...) .list(); But what if I want to apply these criteria not to all operations of type Operation.class, but only to those of types: OpA2 + OpB1 + OpB3 + OpC?
My Question: How can I do it using Hibernate Criteria only? No HQL, please.
Note: I don't know if I should view this problem as "querying more than one class" (where all of them have fields with the same names as the ones I am querying), or if I view it as "restricting a query by a list of subclasses".
Edit: If I could create an interface TheOnesIWant, and then make classes OpA2, OpB1, OpB3 and OpC implement this interface, this would yield the result I want: session.createCriteria(TheOnesIWant.class) But I can't do this, because I only know the classes I want to query at runtime. The above class hierarchy is just an example.