OK, so
http://www.hibernate.org/118.html#A11 says to do it with a composite key mapping and a set.
What's the right kind of HQL to use to query this efficiently? Some people are having troubles with it, for example
http://forum.hibernate.org/viewtopic.php?t=932971. If, for instance, I want to get all (and only) the "memberOf" persons for account 1, what HQL would I write?
What I really want is something like a Map that contains a Set. In other words, I'd like for Account to contain a Map, indexed by account_to_person.key, with values that are the Sets of all Persons that exist in the relationship table with that key. For example, in the case above, I'd like account 1 to have a Map containing "memberOf" and "managerOf" as keys; the value of account1.get("memberOf") would be a set containing persons 1 and 2, and the value of account1.get("managerOf") would be a set containing person 3.
I think this is very close to what
http://forum.hibernate.org/viewtopic.php?t=933914 is asking for. I couldn't find any feature request for it in Hibernate2 *or* Hibernate3. So I made one:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-250
Until then, we'll hide the details of the relationship access behind getter methods, so we get the API we want (which is very much of the form "class Account { public Set getPersonsWithRelationship (String relationshipKey); ... }"). Be nice to have Hibernate do it, but until then....
Cheers!
Rob