cannot insert explicit value for identity column in table '' when identity_insert is set to off

Description

I am getting the error
{"could not insert: [OfficeSuite.AP.Entity.TravelInvoice#2573][SQL: INSERT INTO tbl_ap_travelinvoice (IsPushedToTD, ID) VALUES (?, ?)]"}
Cannot insert explicit value for identity column in table 'tbl_ap_travelinvoice' when IDENTITY_INSERT is set to OFF.

The above error is happeneing for the tables where i am using with JoinedSubClass . all othere tables are working fine.

below is my code for mapping the table

public class APInvoiceMap : ClassMap<APInvoice>
{
public APInvoiceMap()
{
ImportType<APInvoiceItemLookUp>();
Table("tbl_ap_invoice");
Id(x => x.Id).Column("ID").GeneratedBy.Native();

References(x => x.ItemStatus).Column("StatusCode").Cascade.None();

.KeyColumn("InvoiceID").Cascade.AllDeleteOrphan().Table("tbl_ap_invoiceitem").Inverse().Not.LazyLoad()
;
HasMany(x => x.InvoiceServiceMappings)
.KeyColumn("InvoiceID").Cascade.AllDeleteOrphan().Table("tbl_ap_invoiceservicemapping").Inverse().Not.LazyLoad()
;
HasMany(x => x.APCreditNoteInvoiceItems)
.KeyColumn("InvoiceID").Cascade.All().Table("tbl_ap_creditnoteinvoiceitem").Inverse().Not.LazyLoad()
;

JoinedSubClass<TravelInvoice>("ID", m =>
{
m.Table("tbl_ap_travelinvoice");

m.Map(x => x.IsPushedToTD).Column("IsPushedToTD");

m.HasMany(x => x.TravelInvoiceItemList)
.KeyColumn("InvoiceID").Cascade
.AllDeleteOrphan().Table("tbl_ap_travelinvoiceitem")
.Inverse().LazyLoad();
m.HasMany(x => x.TravelRequestItemList)
.KeyColumn("TravelInvoiceID").Cascade.AllDeleteOrphan().Table("tbl_ap_travelrequestitem").Inverse().LazyLoad();

});

}
}

Environment

None

Activity

Show:

Oskar BerggrenNovember 14, 2012 at 11:48 AM

Resolving as external issue:

The mapping you show is not NHibernate's built-in mapping-by-code facility, but from Fluent NHibernate, an addon tool with its own issue tracker.

I doubt that you are using NHibernate 1.2.1, since neither mapping-by-code nor Fluent NHibernate work with it.

Also, when you are using joined-subclass, there must be a way for NHibernate to match the rows to the parent table. This can be specied using the <key> clause in traditional XML-based mapping. I suspect that Fluent NHibernate might default this to use a shared primary key. You either need to override that behavior or allow NHibernate to manage the primary keys in the child tables.

External Issue

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created November 14, 2012 at 11:30 AM
Updated November 14, 2012 at 11:48 AM
Resolved November 14, 2012 at 11:48 AM
Who's Looking?