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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:17:26+00:00 2026-05-11T22:17:26+00:00

Currently I have database with the following associations: One Client to Many Intakes One

  • 0

Currently I have database with the following associations:

  • One Client to Many Intakes
  • One Intake to Many CaseManagements
  • One CaseManagement to Many Interventions
  • Client, Intake, CaseManagement are single classes per table
  • Intervention is a class-hierarchy-per-table.

Currently, if I do something like this:

var client = new Client();
clientRepo.Add(client);

var intake = new Intake();
client.Add(intake);

var caseMan = new CaseManagement();
intake.Add(caseMan);

clientRepo.Update(client);

Everything works fine, and NHibernate creates a Client, then an Intake and then a CaseManagement in the database (all appropriately linked).

However, if do the following:

var client = new Client();
clientRepo.Add(client);

var intake = new Intake();
client.Add(intake);

var caseMan = new CaseManagement();
intake.Add(caseMan);

var intervention = new SubIntervention();
caseMan.Add(intervention);

clientRepo.Update(client);

It screwed up and runs the following SQL:

INSERT INTO TblClient ... (*)
INSERT INTO TblIntake ...
INSERT INTO TblCaseManagement ...
INSERT INTO TblClient ... (*)

Where the starred lines are identical. I have no clue why using inheritance is causing this.

Here is my mapping for my Intake class (which is pretty much the same as Client and CaseManagement).

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="WebTracker4"
                   namespace="WebTracker4.Domain">

<!-- Class Mapping -->
<class name="Intake" table="TblIntake">

<!-- Id -->
<id name="Id" column="IntakeId">
  <generator class="sequence">
    <param name="sequence">IntakeSequence</param>
  </generator>
</id>

<!-- TCN -->
<version name="Tcn" column="IntakeTcn" type="Int64" />

<!-- Client -->    
<many-to-one name="Client" column="ClientId" class="Client" />

<!-- Case Management -->    
<bag name="CaseManagements" inverse="true" cascade="all" table="TblCaseManage" order-by="CaseManageId desc">
  <key column="IntakeId" />
  <one-to-many class="CaseManagement" />
</bag>

<!-- Properties -->
...

</class>
</hibernate-mapping>

Here’s my mapping for the Intervention class hierarchy:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="WebTracker4"
               namespace="WebTracker4.Domain.Interventions">

<!-- Class Mapping -->
<class name="Intervention" table="TblIntervention" abstract="true">

<!-- Id -->
<id name="Id" column="InterventionId">
  <generator class="sequence">
    <param name="sequence">InterventionSequence</param>
  </generator>
</id>

<!-- Discriminator -->
<!-- This is used so that we can have Intervention subclasses. -->
<discriminator column="InterventionType" type="String" />

<!-- TCN -->
<version name="Tcn" column="InterventionTcn" type="Int64" />  

<!-- Case Management -->
<many-to-one name="CaseManagement" column="CaseManageId" class="WebTracker4.Domain.CaseManagement, WebTracker4" />

<!-- Properties -->    
....

<!-- Assessment Subclass -->
<subclass name="SubIntervention" discriminator-value="Sub">
  ...
</subclass>

</class>

What am I missing that is making it try to re-add the Client entity? What also may be of note is that if I screw up the column names in the subclass, NHibernate doesn’t say anything.

This is driving me crazy, please help 🙂

  • 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-11T22:17:26+00:00Added an answer on May 11, 2026 at 10:17 pm

    I figured out the problem. It was because I was using the InterventionType column as both the discriminator and a property. I found that if I changed

    <discriminator column="InterventionType" type="String" />
    

    into

    <discriminator column="InterventionType" type="String" insert="false" />
    

    the problem went away.

    I think it’s because you’re basically telling NHibernate not to manage the discriminator column.

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

Sidebar

Related Questions

Currently I have a database with the following relationships: One Client has multiple Entities
I currently have the following funciton in an oracle database that returns a concatenated
I currently have the following code that retrieves data from the database and then
Currently I have the following table in my database |AnswerID|QuestionID|AnswerText| |21|2|User| |22|2|Admin| |23|2|Guest| |24|2|User2|
I currently have a database call which works in one area, but not another.
Framework: Rails 2.3.8 Database; PostgreSQL I currently have the following SQL statements (generated by
I currently have the following code coming from a database table: <h1 class=widgetHeader>My Friends</h1>
I currently have a MySQL database which I was hoping to use to store
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I currently have a bunch of SQLCHAR objects from a database query. The query

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.