Hi,
I've a problem while trying to use a many-to-many association.
Here is the Tables :
Code:
FCONTACT (ID_CONTACT, CONTACT_NAME)
FCLIENT(CODECLIENT, CLIENT_NAME)
FCONTACT_CLIENT(ID_CONTACT, CODECLIENT)
As you can see, we can have more than one contact for each client, and more than one client for each contact.
Here are the mapping configuration files :
Code:
  <class name="Contact" table="FCONTACT">
    <id name="ContactID">
      <column name="CONTACT_ID" not-null="true"/>
      <generator class="assigned"/>
    </id>
    <bag name="Clients" table="FCONTACT_CLIENT" lazy="false">
      <key column="ID_CONTACT"/>
      <many-to-many class="Client" column="CODECLIENT"/>
    </bag>
  </class>
  <class name="Client" table="FCLIENT">
    
    <id name="CodeClient">
      <column name="CODECLIENT" not-null="true"/>
      <generator class="assigned"/>
    </id>
    <bag name="Contacts" table="FCONTACT_CLIENT" inverse="true" lazy="false">
      <key column="CODECLIENT"/>
      <many-to-many class="Contact" column="ID_CONTACT" />
    </bag>
  </class>
The mapping seems to work :
Code:
NHibernate.Cfg.HbmBinder: 11:52:43,953 INFO  HbmBinder:0 - Mapping collection: CACAO_Framework.Contact.Clients -> FCONTACT_CLIENT
NHibernate.Cfg.HbmBinder: 11:52:43,968 INFO  HbmBinder:0 - Mapping collection: CACAO_Framework.Client.Contacts -> FCONTACT_CLIENT
When I load a Contact, the SQL queries are executed :
Code:
Loader:0 - SELECT contacts0_.CODECLIENT as CODECLIENT__1_, contacts0_.ID_CONTACT as ID_CONTACT1_, contact1_.ID_CONTACT as ID_CONTACT1_0_, contact1_.CONTACT_NAME as CONTACT_NAME1_0_ FROM FCONTACT_CLIENT contacts0_ left outer join FCONTACT contact1_ on contacts0_.ID_CONTACT=contact1_.ID_CONTACT WHERE contacts0_.CODECLIENT=@p0
But the collection returned is empty. And I have no exception...
(If I make a HQL query on the same data, it returned a filled collection.)
How can you explain that the mapping seems to be ok but NHibernate returns me a empty collection ?
Regards,