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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:20:11+00:00 2026-06-01T10:20:11+00:00

class A {..} class ContainedA { property of type A and some extra information

  • 0
class A {..} 
class ContainedA { property of type A and some extra information }
class B : A { collection of type ContainedA  }

As you can tell the idea is to be able to contain a single instance of A in several B’s, B itself is also of type A only it can hold other A’s

A and B’s mapping

  <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="REDACTED"
    assembly= "REDACTED">

    <class name="A" table="A" discriminator-value="1">
        <id name="Id" column="Id" type="int" access="field.camelcase-underscore">
            <generator class="identity" />
        </id>

        <discriminator column="Type" type="int"/>

        <subclass name="B" extends="A" discriminator-value="2">
            <bag name="ContainedAs" cascade="all">
                <key column="AInternalId"/>
                <one-to-many class="ContainedA"/>
            </bag>
        </subclass>

    </class>
</hibernate-mapping>

The mapping for ContainedA

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="REDACTED"
    assembly= "REDACTED">

    <class name="ContainedA" table="ContainedA">
        <id name="Id" type="int" access="field.camelcase-underscore" column="Id">
            <generator class="identity" />
        </id>
        <many-to-one name="A" class="A" column="ContainedAInternalId" cascade="save-update"/>
        <property name="SomeOtherInfoString" column="SomeOtherInfoString" not-null="true"/>
    </class>
</hibernate-mapping>

My issue is that when I save the container B it’s not saving it’s ContainedAs collection and not the actual A’s contained.
This is supposed to be robust, B can be assigned both existing and none existing As and i want to perform a single session.Save(B) and have everything saved.

Your help in the matter would be greatly appreciated.

EDIT: found an error in one of the original HBM’s fixed it, still not working

  • 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-01T10:20:13+00:00Added an answer on June 1, 2026 at 10:20 am

    This isn’t a complete answer, rather a workaround which resolved the issue.

    (Copied from my comment)

    “I’ve somewhat resolved the issue by moving the bag from B to a
    concrete subclass mapping, in my code B is a base subclass itself that
    has two different implementation, apparently Nhibernate just ignored
    the bag because it was on a subclass base mapping.”

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

Sidebar

Related Questions

I have a module which does property injection for some particular type such as
In Type member support in LINQ-to-Entities? I was attempting to declare a class property
How can I format all td elements contained in a table with class myclass
I'm trying to write my first iterator class / container type. Basically, I want
I need to check if a certain property exists within a class. Please refer
I created a class library which is contained of WPF Windows and some user
My task Create a UserControl which should be able to contain any visual child
I'm looking for a way to parse c++ code to retrieve some basic information
I have a container class for adding some properties to standard data types like
I am currently trying to profile a class contained in a different assembly. To

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.