-->
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: Using MySQL, need to qualify on two collection sizes
PostPosted: Tue Dec 23, 2003 12:12 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:20 pm
Posts: 43
I've read the FAQ at http://www.hibernate.org/118.html that describes how to place a condition on a collection size using MySQL (which does not support subqueries).

My problem is that I have to qualify by two collection sizes.

Briefly, I have a Parent object that has two collections - childset1 and childset2 (both are implemented as separate tables that have a many-to-one back to the parent). I need to select parents in which both collections have a non-zero count.

My original HQL (before I was reminded that MySQL versions < 4.1 do not do subqueries) was:

select from parent where childset1.size > 0 and childset2.size > 0

Not sure how to apply one condition after the other. I thought maybe I could use a collection filter to apply the second condition, but the syntax does not support it. Any ideas on how to do this.

The approach I'm using now is to use the tip from the above FAQ to qualify on the first set:

select parent from parent, child1 in parent.childset1
group by parent having count(child1) >= 1

The iterate through this collection checking the "childset2.size()" function for each item in the collection.

This just seems awfully inefficient.

Thanks for any and all ideas/suggestions.


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.