I use an domain object delegation with a composite id projno and index. In this object i insert a bag. When i create a new delegation without voucheurs and want to save it the following exception raised:
NHibernate.PropertyAccessException : Invalid Cast (check your mapping for property type mismatches); setter of domain.Delegation
----> System.InvalidCastException : Die angegebene Umwandlung ist ungültig.
In other domain objects i use one key-column and everything works fine. What is wrong in this implementation?
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="domain" assembly="Base">
<class name="Delegation" table="delegation">
<composite-id unsaved-value="none">
<key-property name="ProjNo" column="projno" access="field.pascalcase-underscore" />
<key-property name="Index" column="index" access="field.pascalcase-underscore" />
</composite-id>
<bag name="Voucheur" access="field.pascalcase-underscore" lazy="true" inverse="true" cascade="all">
<key>
<column name="projmo"/>
<column name="index"/>
</key>
<one-to-many class="Voucheur" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="domain" assembly="Base">
<class name="Voucheur" table="voucheur">
<id name="VoucheurNo" column="voucheurno" access="field.pascalcase-underscore">
<generator class="assigned" />
</id>
<many-to-one not-found="ignore" name="Einsatz" access="field.pascalcase-underscore">
<column name="projnp"/>
<column name="index"/>
</many-to-one>
</class>
</hibernate-mapping>
public class Delegation
{
private string _ProjNo;
public virtual string ProjNo
{
get { return _ProjNo; }
set { _ProjNo = value; }
}
private int? _Index;
public virtual int? Index
{
get { return _Index; }
}
private IList<Voucheur> _Voucheurs = new List<Voucheur>();
public virtual IList<Voucheur> Voucheurs
{
get { return _Voucheurs; }
}
}
public class Voucheur
{
protected int? _VoucheurNo;
public virtual int? VoucheurNo
{
get { return _VoucheurNo; }
set { _VoucheurNo = value; }
}
protected Delegation _Delegation;
public virtual Delegation Delegation
{
get { return _Delegation; }
set { _Delegation = value; }
}
}