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: Find an object with a list where an element of the list=valu
PostPosted: Tue Aug 15, 2006 4:15 pm 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
Hibernate version:3.1
How to find an object with a list where an element of the list equal some value?
For example, I have such class:
Code:
class MyClass{
   List<String> myList;
}

I want to do something like this:
Code:
from MyClass o where o.myList='ABC'

Of course it doesn't work.
How can I do this? Is this possible at all?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 5:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Check out the ref docs section 14.9. Here's the pertinent paragraph:
Quote:
HQL functions that take collection-valued path expressions: size(), minelement(), maxelement(), minindex(), maxindex(), along with the special elements() and indices functions which may be quantified using some, all, exists, any, in.


So for the simple case you're asking about, it would be
Code:
from MyClass o where 'ABC' in elements(o.myList)

_________________
Code tags are your friend. Know them and use them.


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.