Hi, could somebody please review my source and let me know where I am going wrong. I am trying to insert a new application record and am receiving an exception when I try session.Flush().
Here is the application mapping (have changed some values for display purposes):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="..." namespace="...">
<class name="Application" table="APPLICATION">
<id name="UniqueId" column="COUNTER">
<generator class="sequence">
<param name="sequence">MySQ</param>
</generator>
</id>
<property name="CreatedDate" column="CREATE_DATE"/>
<property name="CreatedBy" column="CREATE_BY" type="AnsiString"/>
...
<many-to-one name="ApplicationType" column="APPLICATION_CODE" class="ApplicationTypeCode" fetch="join" lazy="false" property-ref="CodeValue"/>
<many-to-one name="ResultCode" column="RESULT_CODE" class="ApplicationResultCode" fetch="join" lazy="false" property-ref="CodeValue"/>
<property name="ApplicationCost" column="COST" type="AnsiString"/>
</class>
</hibernate-mapping>
Here is the class for Application:
using System;
using System.Collections.Generic;
using System.Text;
namespace ...
{
public class Application: ICreation
{
private int? mUniqueID;
public virtual int? UniqueId
{
get { return mUniqueID; }
set { mUniqueID = value; }
}
private DateTime? createdDate;
private string createdBy;
public virtual string CreatedBy
{
get { return createdBy; }
set { createdBy = value; }
}
public virtual DateTime? CreatedDate
{
get { return createdDate; }
set { createdDate = value; }
}
private ApplicationTypeCode mApplicationType;
public virtual ApplicationTypeCode ApplicationType
{
get { return mApplicationType; }
set { mApplicationType = value; }
}
private ApplicationResultCode mResultCode;
public virtual ApplicationResultCode ResultCode
{
get { return mResultCode; }
set { mResultCode = value; }
}
private string mApplicationCost;
/// <summary>
/// Gets or sets the application cost, populated from the application type code
/// </summary>
/// <value>The application cost.</value>
public virtual string ApplicationCost
{
get { return mApplicationCost; }
set { mApplicationCost = value; }
}
}
}
Here is the class for ICreation:
namespace ...
{
public interface ICreation
{
string CreatedBy
{
get;
set;
}
Nullable<DateTime> CreatedDate
{
get;
set;
}
}
}
Here is the mapping for codes:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="..." namespace="...">
<class name="CodeListItem" table="CODES" discriminator-value="0">
<cache usage="read-only"/>
<composite-id >
<key-property name="CodeListId" column="APP_DATA_CODE"/>
<key-property name="CodeValue" column="APP_CODE"/>
</composite-id>
<discriminator column="APP_DATA_CODE" type="Int32"/>
<property name="CodeValue" column="APP_CODE" type="AnsiString"/>
<property name="CodeDescription" column="CODE_DESC" type="AnsiString"/>
<property name="CodeListId" column="APP_DATA_CODE" type="AnsiString"/>
</class>
<subclass name="ApplicationTypeCode" discriminator-value="225" extends="CodeListItem">
<property name="CodeValue" column="APP_CODE" type="AnsiString"/>
<property name="ApplicationCost" column="PARENT_APP_CODE" type="AnsiString"/>
<property name="ValidFor" column="APP_TEXT" type="AnsiString"/>
</subclass>
<subclass name="ApplicationResultCode" discriminator-value="325" extends="CodeListItem">
<property name="CodeValue" column="APP_CODE" type="AnsiString"/>
</subclass>
</hibernate-mapping>
The following is the CodeListItem class
namespace ...
{
public class CodeListItem
{
private string mCodeValue;
public virtual string CodeValue
{
get { return mCodeValue; }
set { mCodeValue = value; }
}
private string mCodeDescription;
public virtual string CodeDescription
{
get { return mCodeDescription; }
set { mCodeDescription = value; }
}
private string mCodeListID;
public virtual string CodeListId
{
get { return mCodeListID; }
set { mCodeListID = value; }
}
private DateTime? mDeactDate;
public virtual DateTime? DeactDate
{
get { return mDeactDate; }
set { mDeactDate = value; }
}
public override bool Equals(object obj)
{
bool equal = false;
CodeListItem item = obj as CodeListItem;
if(item != null)
{
if(item.mCodeListID == this.CodeListId && item.mCodeValue == this.CodeValue)
{
equal = true;
}
}
return equal;
}
}
}
Now the error I get when I try a session.Flush is the following:
Unable to cast object of type 'System.String' to type '........BusinessEntities.CodeListItem'
(replaced the namespaces etc with dots)