-->
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: Where clause to know if a collections contains some values
PostPosted: Wed Feb 22, 2006 4:47 pm 
Newbie

Joined: Wed Feb 22, 2006 4:28 pm
Posts: 1
I'm new to Hibernate, and I can't find what i'm searching for. Here is what I want to do. I have a Adresse object which contains a array of long. I want to retrieve all Adresse objects that have at least one value (from a list a provide) in their long array. I'm searching for the HQL query to do this ...

So here is a example, in case I'm not clear enough.
Suppose we have 2 adresses object
Addr1 with longArray containing (1,2,3)
Addr2 with longArray containing (3,4,5,6)
A query could be "give my all adresses with a long array containing the value 1 or 4". In this case, Addr1 and Addr2 would be return. But if I ask for all addresses containing 1 or 2, only Addr1 would be return.

I already try something like
from Adresse where longArray in (1,4)
or
from Adresse where elements(longArray) in (1,4)
but no luck

Here is the mapping on my Adresse object :

Code:
<hibernate-mapping>
  <class name="Adresse" table="adresse">
    <id name="id" column="id_adresse">
      <generator class="sequence">
          <param name="sequence">adresse_id_adresse_seq</param>
      </generator>
    </id>
    <version name="ts" type="timestamp"/>
    <property name="ville"/>
    <property name="province"/>
    <property name="pays"/>
    <array name="longArray" table="adresse_localisation" cascade="all">
      <key column="adresse_id"/>
      <list-index column="index" base="0"/>
      <element type="long" column="localisation_id" />
    </array>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 10:11 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You want the "elements(longArray)" HQL function. With "in" you can check for one number at a time:
Code:
:firstParam in elements(addr1.longArray) or :secondParam in elements(addr2.longArray)
However the documentation (ref docs section 14.9, "Expressions") says that elements() works with "some", "exists", "all" or "any", as well as "in". I've never used any of those but you could experiment. If named parameter "arrayParam" contains an array of longs, then you might find that ":arrayParam any elements(addr.longArray)" does what you want.

Can anyone who has used all of those expressions explain how they're used?


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.