-->
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: Using a collection value in a WHERE condition
PostPosted: Fri Jun 18, 2004 9:34 am 
Newbie

Joined: Wed Apr 14, 2004 4:58 am
Posts: 6
Hi,

i have some persistent objects which contains a set of Long values:

<class name="Task" table="tasks" polymorphism="explicit">
<id name="id" column="id" type="long">
<generator class="com.evermind.tools.hibernate.UniqueIdGenerator"/>
</id>
<!--(some properties)-->

<set name="concerned" table="task_concerned">
<key column="task_id"/>
<element column="user_id" type="long"/>
</set>
<!-- ... -->

The mapping between user and task is non-relational (task contains a list of concerned user ids but there's no constraint that forces the user to exist).

Now i want to query all tasks which contains a certain user id. I tried
"from Task t where elements(t.concerned)=42". This fails because it creates a subselect which is not supported by mysql.

When i try "from Task t where t.concerned=42" i gent an exception that the collection is not indexed.

How must i do this query?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 11:51 am 
Newbie

Joined: Wed Sep 29, 2004 10:45 am
Posts: 6
Hi, did you get a solution?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 4:48 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Well...MySQL supports subqueries since version 4.1.x.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 3:36 am 
Newbie

Joined: Wed Apr 14, 2004 4:58 am
Posts: 6
Yes. One solution is just to use a database with subqueries (most do so).

A different one is to use explicitely a join (left join or cross join).
Something like "from task t left join concerned c where c.user_id=42" or (alternatively usefull in some other cases) "from task t, concerned c where t.id=c.task_id and c.user_id=42" (both are examples and untested but show how it can ce done).

Michael.


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.