I have a class, Document and several sub-classes (Invoice, PurchaseOrder, etc). I’ve added a discriminator to Document like so:
public class DocumentMapOverride : IAutoMappingOverride<Document>
{
public void Override(AutoMapping<Document> mapping)
{
mapping.DiscriminateSubClassesOnColumn("DocumentType");
}
}
My understanding is, if I create an Invoice, it will insert the type name into the DocumentType column. However, when I try to insert the Invoice, I get the following exception.
NHibernate.Exceptions.GenericADOException : could not insert: [MyNamespace.Invoice#101][SQL: INSERT INTO "Document" (Version, DocumentNumber, DocumentDate, DbDate, Sender_id, Receiver_id, SenderAlias_id, ReceiverAlias_id, Process_id, Id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
----> System.Data.SQLite.SQLiteException : Abort due to constraint violation
Document.DocumentType may not be NULL
Any suggestions?
- FluentNHibernate 1.0
- SQLite
- C# / .Net4.0
I wasn’t able to reproduce the problem. I’ve downloaded the latest version of FluentNHibernate 1.1 from here and the following program ran fine:
And here’s the SQL queries executed:
In my test I also used
System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139and targeted .NET 4.0 for this console application. Ran it on Windows 7 x64.