Loading...

nhusers@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[nhusers] Re: Subclass containing a nested collection of subclasses Donovan Groeneweegen Wed Feb 08 08:00:28 2012

Hi Itzik

Here's a simplified version of my mapping using the example I provided
above:

BaseEntity Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test"
namespace="Test.Entities">
  <class name="BaseEntity" table="BaseEntity" dynamic-insert="true"
dynamic-update="true" abstract="true">
    <id name="ID" column="BaseEntityID" type="Int64">
      <generator class="identity" />
    </id>

    <discriminator column="EntityTypeCode" />

    <many-to-one name="EntityType" class="EntityType">
      <column name="EntityTypeCode" />
    </many-to-one>

  </class>
</hibernate-mapping>

EntityA Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test"
namespace="Test.Entities">
  <subclass name="EntityA" extends="BaseEntity" dynamic-insert="true"
dynamic-update="true" discriminator-value="EA">
    <join table="EntityA">
      <key column="EntityA_ID" />

      <bag name="EntityB_Bag" cascade="all-delete-orphan"
inverse="true" lazy="false" batch-size="100">
        <key column="EntityA_ID" foreign-key="EntityA_ID" />
        <one-to-many class="EntityB"/>
      </bag>
    </join>
  </subclass>
</hibernate-mapping>

EntityB Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test"
namespace="Test.Entities">
  <subclass name="EntityB" extends="BaseEntity" dynamic-insert="true"
dynamic-update="true" discriminator-value="EB">
    <join table="EntityB">
      <key column="EntityB_ID" />
    </join>
  </subclass>
</hibernate-mapping>

Regards
Don

On Feb 8, 5:37 am, Itzik Saban <[EMAIL PROTECTED]> wrote:
> hi Donovan,
>
> I get the feeling it has something to do with your mapping. can you
> please show us your mapping?
>
> On 7 פברואר, 14:25, Donovan Groeneweegen <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
>
> > I have the following simplified mapping:
>
> > BaseEntity (abstract)
>
> > EntityA : BaseEntity
>
> > EntityB : BaseEntity
>
> > My inheritance strategy is table-per-subclass, using a discriminator
> > value.
>
> > EntityA needs to contain a collection of EntityB.
>
> > When I try to access the nested subclass (EntityB) collection, I get
> > an exception trying to query the collection. Looking at the SQL
> > generated, I see that the statement is attempting to fetch the ID
> > property of EntityA (the FK on the EntityB table) from the BaseEntity
> > table, instead of from the EntityB table.
>
> > Eg:
>
> > SELECT base.EntityA_ID, base.ID, eb.Name
> > FROM BaseEntity base
> > INNER JOIN EntityB eb ON base.ID = eb.ID
> > WHERE base.EntityA_ID = x
>
> > What I would expect to see is something like this:
>
> > SELECT base.ID, eb.Name
> > FROM BaseEntity base
> > INNER JOIN EntityB eb ON base.ID = eb.ID
> > WHERE eb.EntityA_ID = x
>
> > Any help would be greatly appreciated!
>
> > Regards
> > Don

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.