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?