Version: 1.2.0 bata
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="SCControlFunction" table="SC_CONTROL_FUNCTION">
<id name="IDControlFunction" type="int" column="ID_CONTROL_FUNCTION">
<generator class="native" />
</id>
<property name="ControlFunctionName" type="string" column="CONTROL_FUNCTION_SNAME" length="80" />
<property name="ControlFunctionDesc" type="string" column="CONTROL_FUNCTION_DESC" length="80" />
<property name="CertifyUnit" type="string" column="CERTIFY_UNIT" length="3" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
<bag name="UserFunctions" cascade="all" fetch="select" lazy="false">
<key column="ID_CONTROL_FUNCTION" />
<one-to-many class="SCUserFunctionLink"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="SCUserFunctionLink" table="SC_USER_FUNCTION_LINK">
<composite-id>
<key-many-to-one name="IDUser" class="OCUser" column="ID_USER" />
<key-many-to-one name="IDControlFunction" class="SCControlFunction" column="ID_CONTROL_FUNCTION" />
</composite-id>
<many-to-one name="IDValidation" class="OCUser" column="ID_VALIDATION" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="OCUser" table="OC_USER">
<id name="IDUser" type="int" column="ID_USER">
<generator class="native" />
</id>
<property name="FirstName" type="string" column="FIRST_NAME" />
<property name="LastName" type="string" column="LAST_NAME" />
<many-to-one name="IDOrganisation" class="OCOrganisationHierarchy" column="ID_ORGANISATION" />
<property name="EmailAddress" type="string" column="EMAIL_ADDRESS" />
<property name="JobTitle" type="string" column="JOB_TITLE" />
<property name="JobTitle" type="string" column="JOB_TITLE" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
<bag name="UserFunctions" cascade="all" fetch="select" lazy="true">
<key column="ID_USER" />
<one-to-many class="SCUserFunctionLink"/>
</bag>
</class>
</hibernate-mapping>
Code used for testing:
Code:
using (Session session = new Session())
{
SCControlFunction function = Repository.Get<SCControlFunction>(12125);
Assert.IsNotNull(function);
Assert.AreEqual(12125, function.IDControlFunction);
foreach (SCUserFunctionLink link in function.UserFunctions)
{
Assert.IsNotNull(link);
}
session.Success();
}
I am having a problem in which I get an SCControlFunction object by ID using my own Get function. I also have a class Session which wraps an ISession to allow me to use lazy loading. This class implements IDisposable and in my Dispose method I call session.Flush() etc. The problem is that I get the following error when Flush() is called:
System.ArgumentException: There is a problem with your mappings. You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>.
A ValueType (System.Int32) can not be used with IdentityKey. The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&l ... 26tab%3Dwg
Parameter name: key
Doeas anyone have any idea why I am getting this error. as I can't see any major problems with my mapping files.