-->
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.  [ 2 posts ] 
Author Message
 Post subject: NOT IN with manytomany
PostPosted: Wed Dec 08, 2010 10:22 am 
Newbie

Joined: Wed Dec 08, 2010 10:09 am
Posts: 2
Ok, I've been biting my teeth on this one.

I have a dealer which can have multiple tags, in a manytomany form. Tags are only saved when a dealer has that specific tag. No record is no tag.
Now I'm trying to write a search for dealers which DO NOT have a specific tag.

IN SQL:
select * from dealer d
where d.id not in (select dt.dealer_id from dealer_tag dt, tag t where dt.tag_id = t.id and t.name = 'tagname' );

This works perfectly. In HQL I don't have access to the intersection table, so I started of with something like (grabbing this together, since my code is way more generic)

from Dealer as dealer left outer join dealer.tags as tags
where tags.name not in ('tagname')

but of course this gives me also dealers which are present in the intersection table with a different tag than 'tagname'.

So my question is, how do I correct this HQL so that it corresponds to the SQL above?

I also tried something like this
from Dealer as dealer left outer join dealer.tags as tags
where (from Tag tag where tag.name = 'tagname') not in elements(tags))
but I couldn't get that right either...


Top
 Profile  
 
 Post subject: Re: NOT IN with manytomany
PostPosted: Tue Dec 21, 2010 2:15 pm 
Newbie

Joined: Wed Dec 08, 2010 10:09 am
Posts: 2
I solved this by doing a query of all Dealers minus the ones that DO have the tag. I don't think there is any direct way. Thanks


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