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

1
  • That must be something different, because it is not necessary to reference the PK column explicitely: sqlfiddle.com/#!3/b8839/2
    – user330315
    Commented Mar 20, 2013 at 14:26

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.