java - ManyToMany mapping to include some extra records -
let's have following model:
@entity public class user { ... @manytomany private set<permission> allowedpermissions; ... } @entity public class permission { ... private boolean isdefault; ... }
is possible map user.allowedpermissions
contains both permissions
connected user
, these isdefault = true
not explicitly connected?
i use hibernate jpa provider.
well not possible because don't have enough information permissions in user.
if think @ many-to-many relationship, on database it's relation table between 2 other tables.
now, in user entity you're correctly using set see relations stored in cross table (let's user_permission). @ level you're not able know default permissions, can retrieved via permissiondao (i assume you're using dao/service design, if not adjust needs).
if want superset (allowedpermissions + defaultpermissions), can maybe write utility method @ service layer if like:
getallpermissions(user user) { return userdao.getallowedpermissions(user).addall(permissiondao.getdefaultpermissions()); }
why @ service layer? because need 2 daos @ same time, , don't want inject dao another. let me know if useful.
Comments
Post a Comment