-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Projection and polymorphism
PostPosted: Fri Sep 02, 2011 4:12 am 
Newbie

Joined: Fri Sep 02, 2011 4:00 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.