-->
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: Compare Collections/Lists Elements
PostPosted: Wed Jan 30, 2008 10:29 am 
Newbie

Joined: Mon Aug 27, 2007 11:38 am
Posts: 3
Hi,

I'm trying to verify if some list element is equals to some element of another list. E.g.:

User has a list/collection of AccessPermition;
Place has a list/collection of AccessPermition;

To access a Place, a User must be any AccessPermition contained in Place list of AccessPermition.

i'ld like to implement it using Criteria, but, either solution is welcome ;)

thz...


Top
 Profile  
 
 Post subject: Re: Compare Collections/Lists Elements
PostPosted: Wed Jan 30, 2008 3:54 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Thomastik wrote:
Hi,

I'm trying to verify if some list element is equals to some element of another list. E.g.:

User has a list/collection of AccessPermition;
Place has a list/collection of AccessPermition;

To access a Place, a User must be any AccessPermition contained in Place list of AccessPermition.

i'ld like to implement it using Criteria, but, either solution is welcome ;)

thz...



Umm, you could do something like this:

Code:

select u.id from User u, Place p inner join p.accessPermission pap
where u.id = :user_id and p.id = :place_id and pap members of u.accessPermission
group by u.id
having count(pap) = (select count(pap2) from Place p2 inner join p2.accessPermission pap2 where p2.id = :place_id)



where user_id is the user in question and place_id is a place. If you remove the u.id = :user_id part you get the id of all the users that have access to the given place. There might be some small problems in the HQL since I didn't run it myself.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 8:08 am 
Newbie

Joined: Mon Aug 27, 2007 11:38 am
Posts: 3
Hi farzad.

I don't knew members of "operator". It's a Hibernate function or of some specific DBMS?
Do you think it's possible using Criteria API? Some like contains method of Collections (myCollection.contains(eitherElementOfOtherList)) ...

So, thanks for explain


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 10:43 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Thomastik wrote:
Hi farzad.

I don't knew members of "operator". It's a Hibernate function or of some specific DBMS?
Do you think it's possible using Criteria API? Some like contains method of Collections (myCollection.contains(eitherElementOfOtherList)) ...

So, thanks for explain


It's a HQL expression, look at hibernate document section "14.10. Expressions". I will look if this translates into the Criteria API; however, why do you only want to use Criteria?


Farzad-


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.