Consider classes Account
, RealAccount
, VirtualAccount
, and Operation
such that:
class Account { }
class RealAccount extends Account { String name; }
class VirtualAccount extends Account { }
class Operation { Account account; }
This means that:
- Only
RealAccount
has a field calledname
. Operation
's account can beRealAccount
orVirtualAccount
.
I want to query for all Operation
s that belong to a RealAccount
with a specific name:
session.createCriteria(Operation.class)
.createAlias("account", "_account")
.add(Restrictions.eq("_account.name", "Alice"))
.list();
This fails.
My question: Using the "old" Hibernate Criteria API, how can I query for the account name that exists only when the Operation
's account is a RealAccount
? Maybe something envolving DetachedCriteria
and Subqueries
...