4

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?

danyolgiax
  • 12,798
  • 10
  • 65
  • 116

1 Answers1

6

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

CodeTherapist
  • 2,776
  • 14
  • 24
  • Great! You pointed me in the right direction! I've found this: http://stackoverflow.com/a/2827246/735864 – danyolgiax Sep 14 '12 at 22:15
  • 1
    You 're welcome. Keep also a look at `not-found="ignore|exception"`: specifies how foreign keys that reference missing rows will be handled: ignore will treat a missing row as a null association. – CodeTherapist Sep 14 '12 at 22:21