So far the association works fine (the User class loads the appropriate UserRoles instance when present), but when creating a new User and setting its Roles property to a new instance of UserRoles, the UserRoles object is not saved.
Here is my abridged User.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DistrictObservations.User, DistrictObservations" table="users">
<cache usage="read-write" region="all" />
<id name="ID" column="id" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<!-- snip -->
<one-to-one name="Roles" class="DistrictObservations.UserRoles, DistrictObservations" lazy="false" />
</class>
</hibernate-mapping>
And here is the UserRoles mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DistrictObservations.UserRoles, DistrictObservations" table="user_roles">
<cache usage="read-write" region="all" />
<id name="UserID" column="user_id" type="int" >
<generator class="foreign">
<param name="property">User</param>
</generator>
</id>
<!-- snip -->
<one-to-one name="User" class="DistrictObservations.User, DistrictObservations" lazy="false" constrained="true" foreign-key="FK_user_roles_users" />
</class>
</hibernate-mapping>
Anyone got an idea how to have the UserRoles object saved with the User.ID as its primary key? I've been looking at the documentation, and to be honest, it is not particularly helpful.