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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:47:42+00:00 2026-05-10T15:47:42+00:00

I have a new object with a collection of new objects within it on

  • 0

I have a new object with a collection of new objects within it on some property as an IList. I see through sql profiler two insert queries being executed.. one for the parent, which has the new guid id, and one for the child, however, the foreign-key on the child that references the parent, is an empty guid. Here is my mapping on the parent:

<id name='BackerId'>   <generator class='guid' /> </id> <property name='Name' /> <property name='PostCardSizeId'  /> <property name='ItemNumber' />  <bag name='BackerEntries' table='BackerEntry' cascade='all' lazy='false' order-by='Priority'>   <key column='BackerId' />   <one-to-many class='BackerEntry' /> </bag>  

On the Backer.cs class, I defined BackerEntries property as

IList<BackerEntry> 

When I try to SaveOrUpdate the passed in entity I get the following results in sql profiler:

exec sp_executesql N’INSERT INTO Backer (Name, PostCardSizeId, ItemNumber, BackerId) VALUES (@p0, @p1, @p2, @p3)’,N’@p0 nvarchar(3),@p1 uniqueidentifier,@p2 nvarchar(3),@p3 uniqueidentifier’,@p0=N’qaa’,@p1=’BC95E7EB-5EE8-44B2-82FF30F5176684D’,@p2=N’qaa’,@p3=’18FBF8CE-FD22-4D08-A3B1-63D6DFF426E5′

exec sp_executesql N’INSERT INTO BackerEntry (BackerId, BackerEntryTypeId, Name, Description, MaxLength, IsRequired, Priority, BackerEntryId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7)’,N’@p0 uniqueidentifier,@p1 uniqueidentifier,@p2 nvarchar(5),@p3 nvarchar(5),@p4 int,@p5 bit,@p6 int,@p7 uniqueidentifier’,@p0=’00000000-0000-0000-0000-000000000000′,@p1=’2C5BDD33-5DD3-42EC-AA0E-F1E548A5F6E4′,@p2=N’qaadf’,@p3=N’wasdf’,@p4=0,@p5=1,@p6=0,@p7=’FE9C4A35-6211-4E17-A75A-60CCB526F1CA’

As you can see, its not resetting the empty guid for BackerId on the child to the new real guid of the parent.

Finally, the exception throw is:

'NHibernate.Exceptions.GenericADOException: could not insert: [CB.ThePostcardCompany.MiddleTier.BackerEntry][SQL: INSERT INTO BackerEntry (BackerId, BackerEntryTypeId, Name, Description, MaxLength, IsRequired, Priority, BackerEntryId) VALUES (?, ?, ?, ?, ?, ?, ?, ?)] ---\u003e System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint 

EDIT: SOLVED! The first answer below pointed me into the correct direction. I needed to add that back reference on the child mapping and class. This allowed it to work in a purely .net way – however, when accepting json, there was a disconnect so I had to come up with some quirky code to ‘re-attach’ the children.

  • 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. 2026-05-10T15:47:42+00:00Added an answer on May 10, 2026 at 3:47 pm

    You may need to add NOT-NULL=’true’ to your mapping class:

    <bag name='BackerEntries' table='BackerEntry' cascade='all' lazy='false' order-by='Priority'>   <key column='BackerId' not-null='true'/>   <one-to-many class='BackerEntry' /> </bag> 

    as well as make sure that you have the reverse of the mapping defined for the child class:

    <many-to-one name='parent' column='PARENT_ID' not-null='true'/> 

    I had similar issues with hibernate on my current project with parent-child relationships, and this was a part of the solution.

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer So... use bind variables? You should be using them (via… May 11, 2026 at 3:03 pm
  • added an answer If for some reason you do decide to use the… May 11, 2026 at 3:03 pm
  • added an answer Probably the best way to do this is to read… May 11, 2026 at 3:03 pm

Related Questions

Given a DataSet, I'm left joining DataTables[1-n] onto DataTable[0]. I have created a method
A lot of the time I will have a Business object that has a
Duplicate Modifying A Collection While Iterating Through It Has anyone a nice pattern to
I have an object instance which I access with the ME as it accesses

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.