1

I have an nhibernate xml class (called class1) with the following property:

<many-to-one name="Rank" class="RankColourScheme" column="Rank_" 
property-ref="Rank" not-null="true" fetch="join"/>

The column Rank_ is not the primary key column.

When I use nhibernate to generate the sql script to create the tables, the SQL line is:

alter table dbo.Class1_  add constraint FK_Rank foreign key (Rank_) 
references dbo.RankColourScheme_

This line fails, because the constraint isn't referencing the column.

The actual sql should be:

alter table dbo.Class1_  add constraint FK_Rank foreign key (Rank_) 
references dbo.RankColourScheme_ (Rank_)

Any idea what I am doing wrong with my xml?

Thanks in advance,

Nadia

Nerdia
  • 101
  • 1
  • 9
  • That must be something different, because it is not necessary to reference the PK column explicitely: http://www.sqlfiddle.com/#!3/b8839/2 –  Mar 20 '13 at 14:26

1 Answers1

1

have a look at : NHibernate - Mapping a String Foreign Key

you need to define it as:

<bag name=”Inventory” table=”INVENTORY” lazy=”true”>
 <key column=”ID” property-ref=”OID” />
 <one-to-many class=”GuitarStore.Common.Inventory” />
 </bag>

also this was intially but in nhibernate https://nhibernate.jira.com/browse/NH-1272, and it is fixed in 2.1.0Alpha1.

Community
  • 1
  • 1