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: strange problem ...
PostPosted: Mon Jul 09, 2007 7:59 am 
Newbie

Joined: Wed Jun 20, 2007 6:16 am
Posts: 6
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,


Last edited by Romain007 on Wed Jul 11, 2007 10:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 11:03 am 
Newbie

Joined: Wed Jun 20, 2007 6:16 am
Posts: 6
Alone in the dark ????


Last edited by Romain007 on Wed Jul 11, 2007 10:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 11:24 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
Quote:
Code:
<bag name="Contacts" table="FCONTACT_CLIENT" inverse="true" lazy="false">
      <key column="CODECLIENT"/>
      <many-to-many class="Contact" column="ID" />
    </bag>


shouldn't that be

Code:
<bag name="Contacts" table="FCONTACT_CLIENT" inverse="true" lazy="false">
      <key column="CODECLIENT"/>
      <many-to-many class="Contact" column="ID_CONTACT" />
    </bag>


if that was indeed the problem, it's still weird that it doesn't cause an exception

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:53 am 
Newbie

Joined: Wed Jun 20, 2007 6:16 am
Posts: 6
It's just an error in the post, not in the code...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 10:04 am 
Newbie

Joined: Wed Jun 20, 2007 6:16 am
Posts: 6
up


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.