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: Cannot set criteria on subclasses in a HQL join
PostPosted: Wed Nov 08, 2006 5:51 am 
Newbie

Joined: Thu Dec 22, 2005 4:50 am
Posts: 10
As far as i can see, HQL works with mapped associations. I want to be able to set criteria on a subclass for an association (where only the superclass is mapped to the class i want to return)

Say I have the following structure :


ClassA
PropertyA

ClassA2 (Inherited from ClassA)
PropertyB

ClassA3(Also inherited from ClassA)
PropertyC


ClassB (has a mapped association to class A)

I want to do something like this :
select ClassB classB from classB where classB.ClassA2.PropertyB = ' '
Notice i only want to fetch ClassA2 objects with the PropertyB criteria.

but how can i specify criteria for the subclass? The class 'ClassA2' is not mapped to ClassB, only ClassA is so only set criteria using 'PropertyA'

If i do this :

'select ClassA from ClassA classA where ClassA.PropertyA = 'something', it will return the correct subclass (either ClassA, A2, or A3)'

it returns me classA, what i want is Class B

Any Ideas? Ive had a look around and cannot seem to find any similar problems.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 9:03 pm 
Newbie

Joined: Thu Dec 22, 2005 4:50 am
Posts: 10
Update : I can do this with subselects, as i thought originally, but speed is a concern, and true enough it is slow.

e.g.

Select classB from ClassB classB where ClassB.ClassA in (select classA2 from ClassA2 classA2 where ClassA2.PropertyB = "something")

Is there any other way?


Top
 Profile  
 
 Post subject: Solution and question
PostPosted: Thu Jan 04, 2007 4:34 am 
Newbie

Joined: Thu Jan 04, 2007 4:11 am
Posts: 1
Hi.

Did you ever find out a solution for this ?

I have the same problem and solved it by doing a specific join on the subclass:

select classB from ClassB classB, classB.ClassA classA, ClassA2 classA2 where classA.id = classA2.id and classA2.PropertyB = ' '

It works - but I don't find it very pretty.

Regards
Carsten


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.