-->
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: Mapping a sub-collection e.g. Map<String,Set<String>
PostPosted: Thu Jun 05, 2008 7:48 am 
Newbie

Joined: Wed Feb 21, 2007 6:29 am
Posts: 5
Hibernate version: 3.2.6 GA

Name and version of the database you are using: Oracle 9.2

I'm looking for a way to map a table as a Map of Sets to implement a simple ACL. I have a class that contains the following:

Code:
    Map<String,Set<String>> permissions;

    void addPermission(String user, String permission) {
        permissions.get(user).add(permission);
    }

    void removePermission(String user, String permission) {
        permissions.get(user).remove(permission);
    }
   
    boolean hasPermission(String user, String permission) {
        return permissions.get(user).contains(permission);
    }


(The code above is simplified for the purposes of illustrating the problem and does not check for nulls, but the principle is the same). Ideally I'd like to map this onto a single table, so something like the following:

Code:
OBJECTID USER PERMISSION
1        one  read
1        one  write
1        two  read


Would result in an object that is roughly equivalent to:

Code:
Set setOne = new HashSet();
setOne.add("read");
setOne.add("write");
map.put("one", setOne);
Set setTwo = new HashSet();
setTwo.put("write");
map.put("two", setTwo);


Is there any way to map this using HBM? Nothing I could come up with by reading the docs seems to work. If not, what would be a recommended way of representing such an association?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 11:41 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
What's the issue with implementing this through a many-to-many relationship?

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=19mappingmanytomanyrelationships

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 12:27 pm 
Newbie

Joined: Wed Feb 21, 2007 6:29 am
Posts: 5
How do I map a persistent class to a java.util.Set? All the examples of many-to-many associations that I can find map one persistent class to another.

I got as far as:

Code:
        <map name="permissions" table="PERMISSIONS">
            <key column="OBJECTID" />
            <map-key column="USER" type="string" />
            <many-to-many column="PERMISSION"/>
        </map>


hbm2ddl chokes on that with

hbm2ddl wrote:
Schema text failed: An association from the table PERMISSIONS does not specify the referenced entity


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.