-->
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: HQL Howto: All T w/collection T.c having certain elements?
PostPosted: Sun Feb 13, 2005 5:16 pm 
Newbie

Joined: Sun Feb 13, 2005 5:00 pm
Posts: 5
Hibernate version: 2.1.7
MySQL 4.1

I have a class T with a set of Strings T.c. I wish to retrieve all T whose T.c contains all members of a set of Strings s. I hope to express this in HQL, since I want to do paged retireval. Can it be done?

The set is mapped like so:

Code:
    <set name="c" table="c" lazy="false" inverse="false"
       cascade="none" sort="unsorted">
        <key column="t_id"/>
        <element column="the_string" type="string" not-null="false" unique="false" />
    </set>


I can retrieve Ts having any single given String in T.c with

Code:
    select t from T t
        left join t.c c
        where c = ?


which is simple enough. Can I do what I'm hoping to do?

Many thanks for any help.

_________________
--
Jonathan Feinberg jdf@pobox.com Medford, MA
http://MrFeinberg.com/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:55 pm 
Newbie

Joined: Sun Feb 13, 2005 5:00 pm
Posts: 5
Based on a clever example from the docs, I have come up with an answer to my own question:

Code:
select t from T t
    join t.c c
    where c in (:required_values)
    group by t.id
    having count(c) = :required_values_count

_________________
--
Jonathan Feinberg jdf@pobox.com Medford, MA
http://MrFeinberg.com/


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.