Hello,
I have read the documentation about the ternary associations
http://www.hibernate.org/hib_docs/v3/re ... ns-ternary
but the two hbm examples do not exactly apply to us (although the second one is very close). In our case we need association many-to-many between three objects so that any of the three objects can have either set of pairs of any combination of the other two objects or a map in which the key is the second object and the value is a set of the third objects (more explanation below).
The example in the link provided creates a map where the key is the second object but the value is a single third object (instead of the set of third objects).
To be precise, the three types of objects are: users, roles and sites. One user has multiple roles for each site. One role has multiple users for each site. One site has multiple users for each role.
Therefore, we need to implement methods for each combination:
User.getRolesForSite(Site) - get a list of roles the user has in the given site
User.getSitesForRole(Role) - get a list of sites in which the user has given role
Role.getUsersForSite(Site) - get a list of users that have the role in given site
Role.getSitesForUser(User) - get a list of sites in which the given user has the role
Site.getUsersForRole(Role) - get a list of users with given role in the site
Site.getRolesForUser(User) - get a list of roles the given user has in the site
In the database we have a table with three columns: userId, roleId and siteId which are foreign keys to tables that represent each domain object.
We do not want to create a separate domain object that would hold these relations (UserRoleSite).
The question is:
Is there an hbm configuration we could apply that would be able to stand for this type of relation? Like I mentioned before, the documentation
http://www.hibernate.org/hib_docs/v3/re ... ns-ternary
(the second example) provides a solution that is a very close to what we want, with the only difference that the documentation example gives IncomingNode.Map<Node, Connection>, which would be converted to our example: Sites.Map<Role, User>, while what we need is an example that would give IncomingNode.Map<Node, Set<Connection>>, which would be converted to our example: Sites.Map<Role, Set<User>>.
Thank you. Please help. Please let me know if I was not clear enough.