4
votes

I've something like this mapping situation in NHibernate:

ClassA
mapping.Id(x => x.Id).Column("rowid").GeneratedBy.Identity().Unique();

ClassB
mapping.Id(x => x.Id).Column("rowid").GeneratedBy.Identity().Unique();
mapping.References<ClassA>(x => x.ClassA).Nullable();

When NHibernate generate the database schema it creates a foreign-key between these tables even if I've specified "Nullable" attribute in mapping declaration. Obivously if I try to save my objects I get a foreign-key constraint error and if I remove manually the foreign-key from database, it works like a charm.

How to tell NHibernate not to create the foreign-key script in this situation?

1

1 Answers

6
votes

I'm think you should use the foreign-key="none" attribute in your hbm.xml mapping file.