I have a class (CourseEvent) that is mapped to have a bag that is lazy loaded. The bag is of a type that is part of an inheritance hierarchy.
CourseEventLetterHistory inherits from the abstract class LetterHistory, and is mapped as having discriminator value of "E". There are also 2 other subclasses, defined with their own discriminator values - EventBookingLetterHistory (Discriminator = "B") and ContractLetterHistory (Discriminator = "C"). the discriminator column is defined as
Code:
<discriminator column="EventBookingContractIndicator" />
When I explicitly get a list of CourseEventLetterHistory, the sql is executed correctly with
Code:
EventBookingContractIndicator='E'
However, if I first load a CourseEvent, and then access the CourseEventLetterHistory the sql does not include the discriminator value at all. As a result, I'm getting EventBookingLetterHistory records in my collection of CourseEventLetterHistory objects, which is wrong. I'm having trouble determining how to resolve this problem.
relevant mappings below:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Entities"
namespace="Entities" default-access="field.pascalcase-underscore" default-cascade="save-update">
<class name="CourseEvent" table="tblEvents" polymorphism="explicit">
<id name="Id" column="EventID" type="Int32" unsaved-value="0" access="property" >
<generator class="native"/>
</id>
<bag name="LetterHistoryRecords" cascade="all-delete-orphan" access="field.pascalcase-underscore" inverse="true" lazy="true"
generic="true" order-by="LetterHistoryID asc" >
<key column="EventBookingContractId" />
<one-to-many class="CourseEventLetterHistory" />
</bag>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Entities"
namespace="Entities" default-cascade="none" default-access="field.pascalcase-underscore">
<class name="LetterHistory" table="tblLetterHistory" >
<id name="Id" column="LetterHistoryID" type="Int32" unsaved-value="0" access="nosetter.pascalcase-underscore">
<generator class="native"/>
</id>
<discriminator column="EventBookingContractIndicator" />
</class>
<subclass name="Entities.CourseEventLetterHistory, Entities" discriminator-value="E" extends="LetterHistory">
<many-to-one name="trainer" class="Trainer" column="TrainerID" access="field.camelcase-underscore"/>
<many-to-one name="courseEvent" class="CourseEvent" column="EventBookingContractID" access="field.camelcase-underscore" />
</subclass>
<subclass name="Entities.EventBookingLetterHistory, Entities" discriminator-value="B" extends="LetterHistory">
<many-to-one name="eventBooking" class="EventBooking" column="EventBookingContractID" access="field.camelcase-underscore"/>
</subclass>
<subclass name="Entities.TrainerContractLetterHistory, Entities" discriminator-value="C" extends="LetterHistory">
<many-to-one name="trainer" class="Trainer" column="TrainerID" access="field.camelcase-underscore"/>
<many-to-one name="trainerContract" class="TrainerContract" column="EventBookingContractID" access="field.camelcase-underscore"/>
</subclass>
</hibernate-mapping>