A colleague of mine has found a solution to the issue:

The resolution was to create a many-to-one bi-directional mapping from
EntityB back to EntityA.

It seems that doing this helps NH to figure out the FK relationship
between EntityA & EntityB, instead
of trying to create the relationship between the BaseEntity and
EntityB.

Thanks for your time.

On Feb 8, 9:20 am, Donovan Groeneweegen <[email protected]> wrote:
> 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.

Reply via email to