Question

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

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top