Just leant a new term "ternary association". Here is a good link for Hibernate :
http://www.xylax.net/hibernate/ternary.html
So based on this info, I will try to map the class User like this:
<class name="User" table="USERS">
......
<set name="programRoles" table="User_Program_Role">
<key column="USER_ID"/>
<composite-element class="ProgramRole">
<many-to-many name="program" class="Program" column="PROGRAM_ID"/>
<many-to-many name="role" class="Role" column="ROLE_ID"/>
</composite-element>
</set>
......
</class>
Class User {
Set programRoles;
......
}
So now we can:
Set programRoles = user.getProgramRoles();
I hope it works.