-->
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 collection elements
PostPosted: Mon Jun 06, 2005 9:55 am 
Newbie

Joined: Mon Jun 06, 2005 8:50 am
Posts: 2
Hi!

How can I query collection elements? What I mean by that is that persistent object has a property (collections) which holds other (same type) objects. I want to query those objects. I've written the query

select elements(p.Friends) as friends from Person p where friends.Name like '" + searchPattern + "'"

and this produces an error " , expected in SELECT".

What I want from this query (if it is not obvious) is to filter friends collection based on the Name property of the object. The Friends collection holds Person objects -- the same type as the "parent" object.


To iliustrate.
Say I have a persons named A, AA, AAA, and AAAA. Now, A has friends:
AAA and AAAA. And AAAA has friends AA, and AAA.

I want to write a HQL query, that would tell me which persons have a friend named like AA%. The result would return two person objects (A and AAAA).


I looked a filtering the collection, but I don't know how to apply that here, since I have many collections (elements(p.Friends)).


Thanks,
Miha


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 9:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
select f from Person p join p.friends f where f.name like ....


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon Jun 06, 2005 4:03 pm 
Newbie

Joined: Mon Jun 06, 2005 8:50 am
Posts: 2
Gavin,

thanks a lot. I didn't know I can use object's collection as a "table". Thanks again. -- btw, it would be nice if something like that would be mentioned in the docs... (if it is, I didn't find it).

Thanks,
Miha.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 9:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html#queryhql-joins
Kittens is a collection.


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.