-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping a collection...
PostPosted: Thu Apr 20, 2006 4:39 am 
Newbie

Joined: Tue Mar 07, 2006 4:56 am
Posts: 17
Hello together...

I'm trying since quite a while to do a relative simple mapping, but without success. Here is what I want:

I got a table "Country", it contains three fields: ID (GUID), Name (String), ISOCountryCode (String).

I have another table called "Outlet". It contains quite a bit more fields, but also has a field "ISOCountryCode".

What I want to do now, is to get a collection of Outlets from the country. The Country object has an IList for this, which should be populated by nHibernate.

Here is my current mapping, which isn't working:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BS.SCP.Data.Country, BS.SCP.Data" table="Country">

<id name="m_ID" column="id" type="Guid" access="field">
<generator class="guid.comb"/>
</id>


<property name="ISOCountryCode"/>
<property name="Name"/>


<bag name="OutletList" table="Outlet" lazy="false" access="field.pascalcase-m-underscore">
<key column="ID" foreign-key="ISOCountryCode"/>
<one-to-many class="BS.SCP.Data.Outlet, BS.SCP.Data"/>
</bag>
</class>

</hibernate-mapping>

What am I doing wrong?

Kind regards, Marco...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 8:01 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This kind of collection mapping (FK column -> non-PK column) is not supported by NHibernate. Only mapping from FK to PK is supported, i.e. your Outlet table would have to contain field CountryID of type GUID.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 9:04 am 
Newbie

Joined: Tue Mar 07, 2006 4:56 am
Posts: 17
Hi Sergey,

how would the "bag" look like if I used a field "CountryID" in Outlet instead of my ISOCountryCode? I tried something like this:

<bag name="OutletList" table="Outlet" lazy="false" access="field.pascalcase-m-underscore">
<key column="ID"/>
<many-to-many class="BS.SCP.Data.Outlet, BS.SCP.Data" column="CountryID"/>
</bag>

But my OutletList is always empty (it should contain two entries).

Regards, Marco...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 9:56 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
Hi Marco,

here is my suggestion for your problem. It should go like this...
Code:
<bag name="OutletList" table="Outlet" lazy="false" access="field.pascalcase-m-underscore">
<key column="CountryID"/>
<one-to-many class="BS.SCP.Data.Outlet, BS.SCP.Data"/>
</bag>


This assumes that the value of the column "CountryID" in table "Outlet" is equvivalent to the primary key value of the table "Country". Now it's a true PK->FK relationship. That means you will get all outlets to a selected country.

Greetings,
Chavez


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.