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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:15:07+00:00 2026-05-11T05:15:07+00:00

I have a Vessel object that has a one-to-many relationship with a VesselDetail object.

  • 0

I have a Vessel object that has a one-to-many relationship with a VesselDetail object. When I add a VesselDetail object to the Vessel object and try to save the Vessel object, it seems NHibernate does not add the foreign key when inserting the VesselDetail object.

Where am I going wrong here ? I just cannot figure it out.

Error message: BDN.FindVessel.Tests.Integration.NhibernateRepositoryTests.SaveVessel_ShouldAddDetailsToDb_WhenAddedToEntity: NHibernate.Exceptions.GenericADOException : could not insert: [BDN.FindVessel.Domain.VesselDetail][SQL: INSERT INTO BoatsDetails (SaftyGear, OtherMachineryAndGear, Material, Size, Various, TranslatorId, SpeenAndConsumption, MainMachinery, Created, Class, Capasities, Culture, Interior, Electronics, DeckGear) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()] —-> System.Data.SqlClient.SqlException : Cannot insert the value NULL into column ‘BoatId’, table ‘FindVesselTest.dbo.BoatsDetails’; column does not allow nulls. INSERT fails. The statement has been terminated.

public class Vessel {         public virtual int BoatId { get; set; }         public virtual IList<VesselDetail> Details { get; set; }         //... }  public class VesselDetail {         public virtual int VesselDetailId { get; set; }         //some other properties         //.. }  public class VesselMap: ClassMap<Vessel> {     public VesselMap()     {         WithTable('Boats');          Id(x => x.BoatId, 'Id');          //..          HasMany(x => x.Details)             .WithKeyColumn('BoatId') //foreign key in the BoatsDetails table             .Cascade.All();     } }  public class VesselDetailMap:ClassMap<VesselDetail> {   public VesselDetailMap()   {       WithTable('BoatsDetails');        Id(x => x.VesselDetailId, 'Id');        //...   } } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:15:07+00:00Added an answer on May 11, 2026 at 5:15 am

    It seems I was missing some fundamental NHibernate skills. Reading a little bit up on this it seems you need to let the child object be responsible for the one-to-many relation.

    This fixed the problem for me:

    public class VesselMap: ClassMap<Vessel> {     public VesselMap()     {         //...          HasMany(x => x.Details)                 .Inverse()                 .WithKeyColumn('BoatId');     } }  public class VesselDetailMap:ClassMap<VesselDetail> {   public VesselDetailMap()   {       //..         References(x => x.Vessel, 'BoatId')                 .Cascade                 .SaveUpdate();   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has a vessel pressure that is trended every 30
Have a matrix report now that has Position, Hours and Wages for a location
Have a look at one of my websites: moskah.com The problem is that it
Have a really weird one here. The app has two targets, just to be
I have a binary tree, that I am searching: TreeNode<Vessel*>* node = this->tree_->search(PotatoFace); string
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
I have an application where I have a generic object (table) called Hull. Each
Have a bunch of WCF REST services hosted on Azure that access a SQL

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.