-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem for mapping many-to-many
PostPosted: Wed Apr 26, 2006 12:33 pm 
Newbie

Joined: Thu Mar 16, 2006 12:35 pm
Posts: 17
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 ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.