Hello
I try to make a many-to-many mapping with a class Country and a class Vaccination.
That's the mapping file for the Country class :
Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="ng.bcngGeo.Country, mapping" table="country">
<id name="code" column="code_country" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="codeIso" column="code_iso"/>
<property name="name" column="name"/>
<set name="vaccinations" lazy="true" inverse="false" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" cascade="save-update" table="country_vaccination">
<key column="code_country"/>
<many-to-many class="ng.bcngGeo.Vaccination,mapping" column="id_vaccination"/>
</set>
</class>
</hibernate-mapping>
and for Vaccination :
Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="ng.bcngGeo.Vaccination, mapping" table="vaccination">
<id name="code" column="id_vaccination" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="name" column="name"/>
<set name="countries" lazy="true" inverse="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" cascade="save-update" table="country_vaccination">
<key column="code_country"/>
<many-to-many class="ng.bcngGeo.Vaccination,mapping" column="id_vaccination"/>
</set>
</class>
</hibernate-mapping>
The problem is that when I do :
Code:
Vaccination v = new Vaccination("XYZ");
c3.vaccinations.Add(v);
v.countries.Add(c3);
NHDBMgr.getInstance().saveOrUpdateBusinessObject(c3);
an error is throw :
Code:
Exception non gérée : NHibernate.PropertyAccessException: Exception occurred getter of ng.
bcngGeo.Vaccination.code ---> System.Reflection.TargetException: Object does not correspond of target type.
à System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
If I just instantiate a Vaccination object and directly saved it to database it works but when I went to make a link between Vaccination and Country this error is throw.
If I well understand the exception message it's like I don't return the correct type for the property code in the Vaccination class but the code of the property is :
Code:
public virtual int code
{
get { return _code; }
set { _code = value; }
}
Thanks in advance because I didn't see what is wrong ...