anuarneto wrote:
try adding the foreing-key attribut to your key into the bag.
Thanks for the reply. Actually i've tried that and the problem is that it uses the correct column (CountryCode) but it uses the ID instead for the value (so the column/property is correctly taken but the value is not from CountryCode but from CountryID instead).
This is my mapping for the Countries Table:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="BO_Layer"
assembly ="BO_Layer" >
<class name = "Countries"
table= "[dbo].[Countries]"
>
<id name="countryID"
column="`CountryID`"
type="System.Int32"
>
<generator class="assigned" />
</id>
<property
name="countryCode"
column="`CountryCode`"
type="System.String"
length="3"
>
</property>
<property
name="name"
column="`Name`"
type="System.String"
length="12"
>
</property>
<bag name="members" cascade="all-delete-orphan" lazy="false" inverse="true" >
<key foreign-key="countryCode"></key>
<one-to-many class="Members" />
</bag>
</class>
</hibernate-mapping>
And for the Members table:
<property
name="countryCode"
column="`CountryCode`"
type="System.String"
length="3"
>
</property>
<many-to-one
name = "countries"
class = "Countries"
property-ref= "countryCode"
cascade = "save-update"
outer-join = "auto"
insert = "false"
update = "false"
>
<column name="`CountryCode`" />
</many-to-one>
Here is the generated SQL :
SELECT members0_.CountryCode as CountryC8___, members0_.[Member_id] as y1___, members0_.[Member_id] as y1_0_, members0_.[Member_Since] as y6_0_, members0_.[Zipcode] as y4_0_, members0_.[CountryCode] as y8_0_, members0_.[Name] as y2_0_, members0_.[Gender] as y7_0_, members0_.[Town] as y5_0_, members0_.[Street] as y3_0_ FROM [dbo].[Members] members0_ WHERE members0_.CountryCode=@p0
@p0 = '2'
---------------------------------------------
The value '2' is actually ContryID (int) where ContryCode is a string.
Note: Retested in 1.0.3 and i get the same behaviour.