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

  • Home
  • SEARCH
  • 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 6971657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:52:06+00:00 2026-05-27T16:52:06+00:00

I have an identifying relationship between two tables in the database. The parent table

  • 0

I have an identifying relationship between two tables in the database.

The parent table has a primary key that is generated via an Identity. The child table has a primary key that is the identity-generated primary key from the parent table. It’s a true one-to-one.

I’ve tried several mapping strategies, with all sorts of results, none of them perfect.

The parent mapping file has this (notice the Cascade.All() – I expect the parent to manage the relationship):

HasOne(x => x.ChildObject).Cascade.All();

The child mapping has this:

Id(Reveal.Member<ChildObject>("ID"))
.GeneratedBy.Foreign("ParentObject");
HasOne(Reveal.Member<ChildObject, ParentObject>("ParentObject"))
.Constrained()
.ForeignKey();

I changed the object names to protect the innocent.

So here’s what happens. I create an instance of the parent, I create an instance of the child and set the relationships (add the Child to the Parent, and the Parent to the Child).

I run this code:

session.SaveOrUpdate(_Parent);
session.Clear();
transaction.Commit();

What I expect to happen is the Parent gets saved, with the ID being updated in the parent from the database. Then the ID should be set in the Child, and the Child saved.

Instead, the Parent gets saved, but not the Child (I can see the insert statements nHibernate is executing, and the Child object never appears in the database).

The Child has the ID from the parent (it’s being propagated from Parent to Child correctly), but nHibernate doesn’t recognize the Child as dirty (a guess on my part). Even if I explicitly try a SaveOrUpdate on the Child object, it doesn’t get saved.

But it gets a bit weirder. If I attach a collection of dirty objects to the Child, and I call SaveOrUpdate explicitly on the Child, nHhiberante will persist the Child, and the collection – the expected behaviour. But I still have to call it explicitly.

What mistake have I made mapping the Parent-Child relationship?

  • 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-27T16:52:06+00:00Added an answer on May 27, 2026 at 4:52 pm

    My guess is that parent.Id is generated by identity.

    the line session.SaveOrUpdate(_Parent); will save the parent to get its id and cache the Insert of the Child to flush on commit. session.Clear(); will then remove the cached Insert and transaction.Commit(); wont find anything to do.

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

Sidebar

Related Questions

I have a database structure that has two one-to-many relationships. I have a website,
I have a table called Token in my database that represents texts tokenized. Each
I have a large Excel spreadsheet with a column that has an identifying number.
I have a Entity Framework design with a few tables that define a graph.
I have a very subtle bug that I'm having trouble identifying. Background: We have
I have a static std::map<std::string, CreateGUIFunc> in a class that basically holds strings identifying
The AutomationProperties.AutomationId attached property seems to have two purposes: Identifying UI controls during automated
I have a list of dates in a table in a MySQL database (the
Here's an example: Originally I have 3 tables. Table B references Table A. So
I have a list of events which has a UUID identifying the browsers. Given

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.