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...
|