-->
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: Advanced(?) mapping: 2 levels deep "shortcut"
PostPosted: Sun May 29, 2005 4:21 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 7:21 am
Posts: 27
Location: Sweden
Ok, here's the scenario (a common ACL implementation):

- One User can have 0-many Roles
- One Role includes 0-many Permissions

(User m-t-m Role m-t-m Permission)

Now, I realized it would be nifty to be able to get the complete list of permission names (eg "order_add", "order_view", "order_update", etc) for all roles associated with each user, using

Code:
List permissionNames = user.getPermissionNames();


without having to do

Code:
Collection userRoles = user.getRoles();
for ( Iterator ri = userRoles.iterator(); ri.hasNext() ;) {
   Role role = (Role) ri.next();
   Collection rolePermissions = role.getPermissions();
   for ( Iterator pi = rolePermissions.iterator(); pi.hasNext() ;) {
      Permission p = (Permission) pi.next();
      permissionNames.add( p.getName() );
   }
}


The corresponding SQL query would be

Code:
select
   distinct p.name
from
   permission p
   ,role_permission rp
   ,role r
   ,user_role ur
   ,user u
where
   p.id = rp.id
   and rp.id = r.id
   and r.id = ur.id
   and ur.id = u.id
   and u.name = 'foo'

Is this doable with Hib2.x (or 3.x, for that matter) ?

/Mikael


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 4:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at <loader>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 5:09 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 7:21 am
Posts: 27
Location: Sweden
max wrote:
look at <loader>


Doh! I knew I had seen it somewhere...thanks, max.

(Note-to-self: never post late on a sunday night after a heavy night out the day before...bummer.)


Top
 Profile  
 
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.