...Well, that's what I thought - but today I stumbled into a problem that *seems* so trivial that I'm embarrassed to ask for a solution. In short: if I want don't want to map a many-to-many relation as class-to-class, but rather as "class-with-list"
(don't know what to call it..) - then how do I do that?
Here's the DB:
Code:
table user(
integer user_id primary key,
text user_name
);
table user_permission(
integer user_id,
text per_name,
primary key (user_id, per_name),
foreign key (user_id) references user,
foreign key (per_name) references permissions
);
table permissions(
text per_name primary key
);
Now, I don't want to map this as
class User <--m-t-m--> class Permission
..as it would result in having to do..
Code:
User user = ..
Set permissions = user.getPermissions();
for (Iterator i = permissions.iterator(); i.hasNext(); ){
Permission p = p.next();
if (p.getName().equals("order_delete")){
// add menu item "Delete this order"
}
}
..instead of just..
Code:
if (user.getPermissions().contains("order_delete")){
...
}
..that is, if permissions was mapped to a java.util.List in the User class.
It's still a m-t-m relation in the DB though, but as many-to-many requires a class attribute (and there's no Permission class) I'm unsure
how to map this.
TIA
- Mikael.