Hello, I think i've found bug, but maybe it is a feature?
I have
Code:
Order {Client client; boolean collectivePayment}
and a
Code:
Client {}
with descendant classes
Code:
ClientCompany extends Client {}
and
IndividualClient extends Client{}
So i need to find all clients with collectivePayment = true orders. I save order with collectivePayment = true, and client = CompanyClient.
Now i search
Code:
Criteria criteria = session.createCriteria(Order.class);
criteria.add(Restrictions.eq("collectivePayment", true));
criteria.setProjection(Projections.groupProperty("client"));
List<ClientCompany> cclist = new ArrayList<ClientCompany>();
for (Object c : criteria.list()) {
cclist.add((ClientCompany) c);
}
and there is a class cast exception that Client__$$javassist$$... cannot be converted to ClientCompany.
Why does not polymorphism work on projections? Should it? It suppose it should, because when I get an object by Id, i receive ClientCompany, not sole Client.