-->
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.  [ 5 posts ] 
Author Message
 Post subject: Query based on a collection's contents?
PostPosted: Sat Oct 08, 2005 11:53 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 11:23 am
Posts: 36
Location: Lancashire, England
Hallo -- my question is based upon the following example classes:
First, the class MyClass:
Code:
public class MyClass{
    private Long id;
    private Set<MyOtherClass> myOtherClasses;
    public Long getId(){return id;}
    protected Long setId(Long id){this.id=id;}
    public Set<MyOtherClass> getMyOtherClasses(){
        return myOtherClasses;
    }
    public void setMyOtherClasses(Set<MyOtherClass> myOtherClasses){
        this.myOtherClasses=myOtherClasses;
    }
}

And also the class in the collection, MyOtherClass:
Code:
public class MyOtherClass{
    private Long id;
    private String value;
    public Long getId(){return id;}
    protected Long setId(Long id){this.id=id;}
    public String getValue(){return value;}
    public void setValue(String value){this.value=value;}
}


Having established that, my question is -- would it be possible to construct an HQL query that returned instances of MyClass whose collections myOtherClasses contained one or more instances of MyOtherClass whose value attribute was equal to "Hello."?
In (bad) pseudo-code, this might be:
Code:
SELECT from MyClass c WHERE c.myOtherClasses CONTAINS MyOtherClass.value=="Hello."


Sorry -- I know that's a terrible attempt to express it -- that's why I ask for help!
Cheers,
doug.

_________________
Common sense is what tells you the world is flat.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 2:26 pm 
Newbie

Joined: Wed Mar 30, 2005 8:58 am
Posts: 10
Location: São Paulo / Brazil
Well, first of all you could read the HQL sintax documentation.

Secondlly, ... you could read the very well documented HQL sintax ... :)

http://www.hibernate.org/hib_docs/v3/re ... ryhql.html

_________________
www.brunoborges.com.br


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 6:59 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 11:23 am
Posts: 36
Location: Lancashire, England
Fair enough, I was just hoping that someone already knew & could give me some pointers, time & deadlines being what they are.

_________________
Common sense is what tells you the world is flat.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 11:32 am 
Beginner
Beginner

Joined: Tue Jun 29, 2004 12:35 pm
Posts: 21
biot023 wrote:
Fair enough, I was just hoping that someone already knew & could give me some pointers, time & deadlines being what they are.



This might work (tangled w/same problem myself some time ago):

Select aMyClass from MyClass as aMyClass inner join aMyClass.MyOtherClasses as aMyOtherClasses where aMyOtherClasses.value='hello'


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 3:16 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 11:23 am
Posts: 36
Location: Lancashire, England
Cheers for that, man -- that looks bang on!
doug.

_________________
Common sense is what tells you the world is flat.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.