-->
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.  [ 7 posts ] 
Author Message
 Post subject: HOW to put restrictions on map keys
PostPosted: Wed Jan 09, 2008 8:47 am 
Newbie

Joined: Wed Jan 09, 2008 8:33 am
Posts: 4
I have a ternary association, which is represented by the following map:

Code:
<class name="Actor" table="Actor">
    ...
    <map name="fieldValues" table="ActorFieldValues">
      <key column="ownerID" />
      <map-key-many-to-many column="fieldID" class="Field" />
      <many-to-many column="valueID" class="FieldValue" />
    </map>
</class>


I want to find all objects (actors) whose fieldValues keys match some restrictions.
Is it possible to do using a HQL query (especially using Criteria)?

AD


Last edited by adeon on Wed Jan 09, 2008 11:25 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: HOW to put restrictions on map keys
PostPosted: Wed Jan 09, 2008 11:14 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
adeon wrote:
I have a ternary association, which is represented by the following map:

Code:
<class name="Actor" table="Actor">
    ...
    <map name="fieldValues" table="ActorFieldValues">
      <key column="ownerID" />
      <map-key-many-to-many column="fieldID" class="Field" />
      <many-to-many column="valueID" class="FieldValue" />
    </map>
</class>


I want to find all objects (actors) whose fieldValues keys match some restrictions.
Is it possible to do using a HQL query (especially using Criteria)?

AD



I do believe in HQL you can use a join and specify an extra filter for the join by using WITH keyword. This is an example from hibernate document:

Code:
from Cat as cat
    left join cat.kittens as kitten
        with kitten.bodyWeight > 10.0



Is this what you are looking for?


Farzad-


Top
 Profile  
 
 Post subject: Re: HOW to put restrictions on map keys
PostPosted: Wed Jan 09, 2008 11:21 am 
Newbie

Joined: Wed Jan 09, 2008 8:33 am
Posts: 4
farzad wrote:
Code:
from Cat as cat
    left join cat.kittens as kitten
        with kitten.bodyWeight > 10.0



Is 'kittens' a map in this example? I suppose not. When you are referring to kitten.bodyWeight how do you know that you are referring to an attribute of the map key entity, NOT the value?

AD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:14 pm 
Newbie

Joined: Wed Jan 09, 2008 8:33 am
Posts: 4
In other words, I want to set restrictions on map keys using Criteria API.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:17 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
adeon wrote:
In other words, I want to set restrictions on map keys using Criteria API.


I see your point. I am working on an example to see how this works. I will get back to you if I find something useful.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 1:11 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
farzad wrote:
adeon wrote:
In other words, I want to set restrictions on map keys using Criteria API.


I see your point. I am working on an example to see how this works. I will get back to you if I find something useful.


Farzad-



I didn't come up with anything useful here but one thing I recommend you look into is to model the relation as a separate class instead of using the map thing and you will have a lot more control on queries.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 4:29 pm 
Newbie

Joined: Wed Jun 06, 2007 10:17 pm
Posts: 1
With HQL, you can:
supposing a class Actor, actions is a Map property, "suspend" is Map's key,
createQuery("select a from Actor a where a.actions['suspend'] = ?"). ...

but Criteria don't support the criterion based map

_________________
Scott Afable


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