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 9165575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:56:25+00:00 2026-06-17T14:56:25+00:00

I am trying to achieve a HasMany mapping with a non-nullable key column. My

  • 0

I am trying to achieve a HasMany mapping with a non-nullable key column.

My mapping looks like this:

public void Override(AutoMapping<DataExportTable> mapping)
{
    mapping.Table("data_export_tables");
    mapping.Id(x => x.Id).Column("data_export_tables_id")
           .GeneratedBy.Sequence("SQ_DATA_EXPORT_TABLES_ID");
    mapping.HasMany(x => x.Columns)
           .KeyColumn("table_id")
           .Not.KeyNullable()
           .Not.KeyUpdate()
           .Cascade.AllDeleteOrphan();
}

The code to save the entity looks like this:

var table = new DataExportTable("table_name");
table.Columns.Add(new DataExportColumn("column_name"));
session.Save(table);
transaction.Commit();

This throws an exception:

NHibernate.Exceptions.GenericADOException: could not execute batch command.[SQL: SQL not available] —> Oracle.DataAccess.Client.Orac
leException: ORA-01400: cannot insert NULL into (“MYSCHEMA”.”DATA_EXPORT_COLUMNS”.”TABLE_ID”)

Now, I read quite a few posts about this topic and the generally accepted solution seems to be to make the reference bi-directional, i.e. adding a Table property to DataExportColumn and setting that.
Another “hack” is to make the foreign key column nullable.
That’s not what I want. I want NHibernate to insert the ID directly in the INSERT statement.
According to the log file, NHibernate certainly knows the ID at the time it executes the INSERT statement:

NHibernate: select SQ_DATA_EXPORT_TABLES_ID.nextval from dual
NHibernate: Batch commands:
command 0:INSERT INTO data_export_tables (NAME, data_export_tables_id) VALUES (:p0, :p1);:p0 = ‘table_name’ [Type: String (0)], :p1 = 93 [Type: Int32 (0)]

NHibernate: Batch commands:
command 0:INSERT INTO data_export_columns (NAME, data_export_columns_id) VALUES (:p0, :p1);:p0 =
‘column_name’ [Type: String (0)], :p1 = 1228 [Type: Int32 (0)]

As you can see, NHibernate simply ommits the table_id column, although the ID is well known – NHibernate passed it as a parameter to the first insert statement…

  • 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-06-17T14:56:26+00:00Added an answer on June 17, 2026 at 2:56 pm

    So close, you need to set Not.Inverse() as shown in this answer.

    mapping.HasMany(x => x.Columns)
           .KeyColumn("table_id")
           .Not.Inverse()
           .Not.KeyNullable()
           .Not.KeyUpdate()
           .Cascade.AllDeleteOrphan();
    

    I don’t consider making the relationship bidirectional to be a hack and it’s usually necessary for querying.

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

Sidebar

Related Questions

I am trying to achieve something like this. The Expandable List consists of the
Trying to achieve something like this using recursion: if (m > n) return; Foo
Im trying to achieve something like this image: the problem its when im on
Trying to achieve a dynamic UI with facebook like sliding menu and actionbarsherlock .First
iam trying to achieve this exact functionalty: http://jsfiddle.net/exttq/ BUT inside using my PHP, right
I am trying to achieve something like the following but dont know whats wrong:
This is a simplified example of what I am trying to achieve, I'm relatively
I have a IKImageBrowserView embedded inside an NSScrollView. I'm trying achieve scroll bars like
Trying to achieve this with relative/absolute positioning and floating Col1 Col2 ------------------------------------------------------------ - H1
I am trying to achieve a slideUp into view effect, with scrolling. This is

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.