-->
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.  [ 4 posts ] 
Author Message
 Post subject: query help: converting a query that uses sub-selects
PostPosted: Tue Oct 05, 2004 11:06 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
I want to check if any promoter in a collection of promoters is contained by another collection of promoters

this is the query but the DB i need to use doesnt support sub-selects Mysql 4.0, how can I achieve this result without needing sub-selects?

from Promotion p where :promoters in elements(p.promoters)


Promotion.promoters is a many-to-many collection


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 9:30 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
If your association is bidirectionnal you can check the size of promoter.promotions.

I think this is not your case so maybe you can count the number of promotion that holds your promoter :

select count(*) from Promotion promotion join promotion.promoters promoter where promoter=?

I never tried this query so I don't know if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 5:13 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
i've figured out how to get this to work and am now trying to make a Criteria query work instead of straight up HQL

this is the query so far:

select distinct p from Promotion p join p.promoters as promoter where promoter in (:promoters)

i've had no luck with the Criteria querys though


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 08, 2004 2:40 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Maybe something like

session.createCriteria(Promotion.class)
.createAlias("promoters", "promoter")
.add(Expression.in("promoter", ...)

Distinct seems to be impossible with the criteria api (http://forum.hibernate.org/viewtopic.ph ... a+distinct) but maybe you can achieve it at java level with a set


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.