My database contains 3 tables, users, user_roles, and roles. So essentially, there's a many to many relationship between users and roles. The roles table only contains a unique name column with an int id pk.
In my code, I've defined Roles as int enum with the appropriate values that exist in the database. Is it possible to make a domain object User contain a collection of these enum Roles? I can't seem to get it to work with either many-to-many or one-to-many. Any suggestions? Will I have to convert my enum Roles into a class?
Here's a snippet of my failure from my User.hbm.xml:
Code:
<set name="Roles" table="user_roles" fetch="subselect">
<key column="user_id" />
<one-to-many class="MyDomain.Role, MyAssembly" />
</set>
My conclusion is that my approach will not be possible.