-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL query with an entity map
PostPosted: Sun Jul 17, 2005 4:10 am 
Hi all,

I'm using something very simmilar to this one: http://www.xylax.net/hibernate/entitymap.html . In other words I have a map assigning users a kind of boolean flag:
Code:
<class name="Task" table="Tasks">
...
<map name="Persons" table="TaskPersons" >
    <key column="IdTask" />
    <index-many-to-many column="IdUser" class="User" />
    <element column="SendInfo" type="Boolean" />
</map>
</class>


The problem is when I try to query Tasks (Task has a property with key-value collection - User->SendInfo) to get tasks of which user should be notified (exists in Task's Person collection as a Key and has Value (SendInfo) = TRUE). Currently I have a HQL query:
Code:
select t from Task t where (:user = some indices(t.Persons) )

That gives me collection which I have to iterate to get only that tasks, where the given user exists with SendInfo=TRUE. I wonder if it is a way to avoid this iteration. Could anyone help me to modify my query to achieve that?

--
michal


Top
  
 
 Post subject:
PostPosted: Sun Jul 17, 2005 7:48 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Maybe adding "and t.Persons[user] = true" will do it? Or maybe "and indices(t.Persons) = true"?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 17, 2005 9:11 am 
Thank you for quick reply, but I'm still having trouble.

"and t.Persons[:user] = true" -> Index was outside the bounds of the array.
"and indices(t.Persons) = true" -> database server says that the query syntax is invalid (incorrect syntax near....)

tried also :
"and elements(t.Persons)=true" -> Invalid column name 'true'
"and elements(t.Persons)=1" -> subquery returned more than 1 result ....

That brings me an idea to use subquery but I'm still mixed. I think about something like:
Code:
select t from Task t where (:user = some indices( "select * from t.Persons where Value=true"   ) )

Of course this is wrong, I have no idea what to put instead of "select * from t.Persons where Value=true" .

In the docs there are examples of HQL queries with subqueries but only for "set" and "list" collections. I can't find any example with "map".

Any futher suggesions?

--
michal


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.