-->
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: Sun Jun 05, 2005 2:21 pm 
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 p.ID = " + p.ID + "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.


Thanks,
Miha


Top
  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 10:20 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you are missing an AND operator?

Code:
select elements(p.Friends) as friends from Person p where p.ID = " + p.ID +
" AND friends.Name like '" + searchPattern + "'"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 10:20 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you are missing an AND operator?

Code:
select elements(p.Friends) as friends from Person p where p.ID = " + p.ID +
" AND friends.Name like '" + searchPattern + "'"


Top
 Profile  
 
 Post subject: The solution
PostPosted: Mon Jun 06, 2005 4:06 pm 
Actually, the query I wrote was wrong. Hibernate had problems with friends.Name;

Thanks to gavin@hibernate I found out that I can use p.Friends as a table.

So, what I really needed is
Code:
select f from Person p join p.Friends f where f.Name like '%sth%';


Thanks for posting,
Miha.


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