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.  [ 3 posts ] 
Author Message
 Post subject: criteria and polymorphism
PostPosted: Tue Nov 15, 2005 10:32 am 
Newbie

Joined: Mon Sep 08, 2003 3:04 pm
Posts: 12
Hello,

I have a ClassA associated (many-to-one : "link" property) with ClassB which is derived in ClassC and ClassD

I would like to write a Criteria Query on the ClassA, and I want that the associated class be an instance of a particular class.

Something like

session.cretaeCriteria(ClassA.class).add(Restrictions.instanceOf("link", ClassC.class))

Of course the "instanceOf" restrictions doesn't exist but is there a way to do that (without sqlRestriction) ?

Thanks
Franck


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 10:39 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
session.createCriteria(ClassC.class)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 11:18 am 
Newbie

Joined: Mon Sep 08, 2003 3:04 pm
Posts: 12
alesj wrote:
session.createCriteria(ClassC.class)


But If I start the Criteria with this statement, I will obtain as result a collection of ClassC instances. Or I want a collection of ClassA instances.

Actually my workaround is :

criteria = session.createCriteria(ClassA.class)
criteria.createCriteria("link").add(Restrictions("{alias}.class =?", goodClass, Hibernate.String));

But I'm sure (?) there is a better way


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

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.