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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:34:20+00:00 2026-06-05T21:34:20+00:00

I have a web application I’ve developed that has a fairly complex save routine.

  • 0

I have a web application I’ve developed that has a fairly complex save routine. The user builds and modifies a series of plans and then chooses to save the data. All of the additions, deletions, and modifications are saved in one go at this point (all inside a single transaction).

Plan
    Collection Of Child
        Collection of ChildDetail

The bulk of the save is performed by calling SaveOrUpdate on a plan object and letting this save manage the plan and it’s children. I use zero as the unsaved value when I want to insert a new record and use cascade=all-delete-orphan to ensure that if a child object or child detail object is removed on the client side the object is deleted.

I am receiving an exception however when the following happens: A user creates a plan with child objects and saves them. This will save fine.

Plan(id=0)
    Child[0](id=0), Child[1](id=0), Child[2](id=0)

If the user then removes the child objects, and adds new child objects in their place and then attempts to save the changes.

Plan(id=123)
    Child[0](id=0), Child[1](id=0), Child[2](id=0)

This throws a GenericAdoException unable to insert Child with an inner exception “SQL0803 Duplicate Key Value Specified”.

The behavior I’m looking for is for NHibernate to delete the previous Child objects then insert the new ones when SaveOrUpdate is called on the Plan. How can I achieve this while still letting the parent manage the relationships?

  • 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-05T21:34:21+00:00Added an answer on June 5, 2026 at 9:34 pm

    A solution I found for the time being is to pass the Ids of the removed children to the save routine. I then set the ids of the new children to the ids of the removed children. Effectively turning a remove/add into an update.

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

Sidebar

Related Questions

I have web application that is behind a proxy. If the user has logged
I have a web application that has a dynamic javascript calendar, which allows users
I have a web application that I've inherited that has double encoded URLS. If
I have a web application developed with ASP.net and C# that is running on
I have web application deployed on websphere application server 7.0. User logins using /j_security_check.
I have web application written in java using Eclipse. It has just one servlet
I have Web Application in asp.net. Where I am maintaining Session for every User.
I have a web application (WAR) that I want to deploy in Tomcat 5.
I have web application for mobile (developed in .net), I want to use iPhone
I have a web application that needs a database back-end. My back-end is really

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.