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.  [ 5 posts ] 
Author Message
 Post subject: Many-to-Many compilation error due to foreign, primary key
PostPosted: Fri Jul 04, 2008 7:38 am 
Newbie

Joined: Fri Jul 04, 2008 7:28 am
Posts: 3
Hi,

I encounter an error during my mapping compilation :

My error message is :
Foreign key in table MESSAGES must have same number of columns as referenced primary key

But, i though the feeling that both primary and foreign key are properly set.
The set of the Messages.hbm.xml is
Code:
<set name="Campagnes" table="CAMPAGNES" cascade="save-update" lazy="true" inverse="true">
      <key column="FK_MESSAGE" />
      <many-to-many class="planner.objects.Campagnes, planner.objects" column="FK_CAMPAGNE" />
    </set>


The set of the Campagnes.hbm.xml is

Code:

  <set name="MessagesList" table="Messages" cascade="save-update" lazy="true" inverse="false">
      <key column="FK_CAMPAGNE" />
      <many-to-many class="planner.objects.Messages, planner.objects" column="FK_MESSAGE" />
    </set>


In terme of .cs we have the Message set like :

Code:
private Iesi.Collections.ISet campagnes;

        public virtual Iesi.Collections.ISet Campagnes
        {
            get
            {
                return this.campagnes;
            }
        }


and the Campagnes one like :


Code:

private Iesi.Collections.ISet messagesList;

        public virtual Iesi.Collections.ISet MessagesList
        {
            get
            {
                return this.messagesList;
            }
        }



Does it correct?

Many Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 9:31 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The problem is caused your identities. Does one of them have more than one column ? Can you post both identity mappings ?

Btw. I think, your collection properties needs setter, too. But you can define them as private.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: My identities column
PostPosted: Fri Jul 04, 2008 11:30 am 
Newbie

Joined: Fri Jul 04, 2008 7:28 am
Posts: 3
Hi,

I use only 1 column identies like this :

The first whole class Campagnes:

Code:
<class name="planner.objects.Campagnes, planner.objects" table="CAMPAGNES" lazy="true" mutable="true" >
    <id name="Id_campagne" unsaved-value="0" column="ID_CAMPAGNE" type="System.Int32">
      <generator class="native"/>

    </id>
    <property name="Nom" column="NOM" type="String" length="50"/>
     <property name="Dt_Debut" column="DT_DEBUT" type="System.DateTime" />
   <property name="Dt_Fin" column="DT_FIN" type="System.DateTime" />
   <many-to-one name="Clients" column="ID_CLIENT"  not-null="true" fetch="join" cascade="save-update" />

    <set name="MessagesList" table="Messages" cascade="save-update" lazy="true" inverse="false">
      <key column="FK_CAMPAGNE" />
      <many-to-many class="planner.objects.Messages, planner.objects" column="FK_MESSAGE" />
    </set>

    <bag name="ContraintesList" table="Campagnes" cascade="all" fetch="join" inverse="true">
      <key column="ID_CONTRAINTE" />
      <one-to-many class="planner.objects.Contraintes, planner.objects" />
    </bag>

    <property name="Lundi" column="LUNDI" type="System.Int16" />
    <property name="Mardi" column="MARDI" type="System.Int16" />
    <property name="Mercredi" column="MERCREDI" type="System.Int16" />
    <property name="Jeudi" column="JEUDI" type="System.Int16" />
    <property name="Vendredi" column="VENDREDI" type="System.Int16" />
    <property name="Samedi" column="SAMEDI" type="System.Int16" />
    <property name="Dimanche" column="DIMANCHE" type="System.Int16" />
   
  </class>







The Message one :

Code:


<class name="planner.objects.Messages, planner.objects" table="MESSAGES" lazy="true" mutable="true" >
    <id name="Id_message" unsaved-value="0" column="ID_message" type="System.Int32">
      <generator class="native"/>

    </id>
    <property name="Nom" column="NOM" type="String" length="50"/>
    <property name="Duree" column="DUREE" type="System.Double" />
   <property name="Ordre" column="Ordre" type="System.Int16" />

    <set name="Campagnes" table="CAMPAGNES" cascade="save-update" lazy="true" inverse="true">
      <key column="FK_MESSAGE" />
      <many-to-many class="planner.objects.Campagnes, planner.objects" column="FK_CAMPAGNE" />
    </set>




   </class>



Thanks

Gilles M


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:36 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You need a separate table for the many-to-many:

Code:
    <set name="MessagesList" table="Messages_Campagns" cascade="save-update" lazy="true" inverse="false">


The table needs two columns, the pk's of both tables.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Fixed
PostPosted: Mon Jul 07, 2008 3:15 am 
Newbie

Joined: Fri Jul 04, 2008 7:28 am
Posts: 3
Oups,

I'm used to think everything was automatic with NHibernate...
It's clear, i need to create the relation table by my own.

Thanks a lot.
Gilles


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

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.