Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1098399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:34:27+00:00 2026-05-17T00:34:27+00:00

I have a class, Document and several sub-classes ( Invoice , PurchaseOrder , etc).

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:34:28+00:00Added an answer on May 17, 2026 at 12:34 am

    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:

    using System;
    using System.Reflection;
    using FluentNHibernate;
    using FluentNHibernate.Automapping;
    using FluentNHibernate.Automapping.Alterations;
    using FluentNHibernate.Cfg;
    using FluentNHibernate.Cfg.Db;
    using FluentNHibernate.Conventions;
    using FluentNHibernate.Conventions.Instances;
    using NHibernate;
    using NHibernate.Tool.hbm2ddl;
    
    public interface IEntity
    {
        int Id { get; set; }
    }
    
    public abstract class MyBaseClass : IEntity
    {
        public virtual int Id { get; set; }
    
        public class MyBaseClassMap : IAutoMappingOverride<MyBaseClass>
        {
            public void Override(AutoMapping<MyBaseClass> mapping)
            {
                mapping.DiscriminateSubClassesOnColumn("ChildClassType", "MyBaseClassMap");
            }
        }
    }
    
    public class MyFirstChildClass : MyBaseClass
    {
        public virtual string Child1 { get; set; }
    }
    
    public class MySecondChildClass : MyBaseClass
    {
        public virtual string Child2 { get; set; }
    }
    
    public class PrimaryKeyConvention : IIdConvention
    {
        public void Apply(IIdentityInstance instance)
        {
            string table = string.Format("{0}_HiLo", instance.EntityType.Name);
            instance.GeneratedBy.HiLo(table, "next_hi", "100");
        }
    }
    
    public class MyMappingConfig : DefaultAutomappingConfiguration
    {
        public override bool ShouldMap(Type type)
        {
            if (type.GetInterface(typeof(IEntity).FullName) != null)
                return true;
    
            return false;
        }
    
        public override bool AbstractClassIsLayerSupertype(Type type)
        {
            if (type == typeof(IEntity))
                return true;
            return false;
        }
    
        public override bool IsId(Member member)
        {
            return member.Name == "Id";
        }
    
        public override bool IsDiscriminated(Type type)
        {
            if (type.IsAssignableFrom(typeof(MyBaseClass)) || type.IsSubclassOf(typeof(MyBaseClass)))
                return true;
    
            return false;
        }
    }
    
    
    public class Program
    {
        private static ISession InitializeNHibertnat(Assembly mapAssembly)
        {
            var automappingConfiguration = new MyMappingConfig();
    
            var fluentConfiguration =
                Fluently.Configure().Database(SQLiteConfiguration.Standard.InMemory());
    
            fluentConfiguration = fluentConfiguration
                .Mappings(m => m.AutoMappings
                                   .Add(AutoMap.Assembly(mapAssembly, automappingConfiguration)
                                            .Conventions.Add<PrimaryKeyConvention>()
                                            .UseOverridesFromAssembly(mapAssembly)))
                .Mappings(m => m.FluentMappings
                                   .AddFromAssembly(mapAssembly))
                .Mappings(m => m.HbmMappings
                                   .AddFromAssembly(mapAssembly))
                .ExposeConfiguration(cfg => cfg.SetProperty("generate_statistics", "true"))
                .ExposeConfiguration(cfg => cfg.SetProperty("show_sql", "true"))
                .ExposeConfiguration(cfg => cfg.SetProperty("adonet.batch_size", "1"));
    
    
            var configuration = fluentConfiguration.BuildConfiguration();
            var sessionFactory = configuration.BuildSessionFactory();
            var session = sessionFactory.OpenSession();
            new SchemaExport(configuration).Execute(false, true, false, session.Connection, null);
    
            return session;
        }
    
        static void Main()
        {
            var mfcc = new MyFirstChildClass();
            mfcc.Id = 1;
            mfcc.Child1 = "Child One";
    
            var mscc = new MySecondChildClass();
            mscc.Id = 2;
            mscc.Child2 = "Child Two";
    
            var Session = InitializeNHibertnat(Assembly.GetExecutingAssembly());
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(mfcc);
                Session.Save(mscc);
                tx.Commit();
            }
        }
    }
    

    And here’s the SQL queries executed:

    NHibernate: select next_hi from MyBaseClass_HiLo
    NHibernate: update MyBaseClass_HiLo set next_hi = @p0 where next_hi = @p1;@p0 = 2, @p1 = 1
    NHibernate: INSERT INTO "MyBaseClass" (Child1, ChildClassType, Id) VALUES (@p0, 'MyFirstChildClass', @p1);@p0 = 'Child One', @p1 = 101
    NHibernate: INSERT INTO "MyBaseClass" (Child2, ChildClassType, Id) VALUES (@p0, 'MySecondChildClass', @p1);@p0 = 'Child Two', @p1 = 102
    

    In my test I also used System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139 and targeted .NET 4.0 for this console application. Ran it on Windows 7 x64.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets assume I have several <span class='remove-type'> elements on a page. In jQuery document.ready
I have a relationship like this class User include Mongoid::Document include Mongoid::Timestamps embeds_one :setting
I have documents collection Messages in my base (RavenDB) Document definition like: class Message
I have in my html document several div elements with certain css class and
I have a Document class, Intro class and Nav class. The Intro class runs
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
I have the following structure: class User include Mongoid::Document end class Resource include Mongoid::Document
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and
I have a C# class method that return a xml document not file. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.