-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Discriminator not being applied when bag loaded
PostPosted: Tue Jul 03, 2007 10:59 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
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>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 12:16 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Frustrating, but this "isn't an issue". You need to limit the bag in the mapping with
Code:
where="EventBookingContractIndicator = 'E'"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 12:24 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
Thanks for your help marcal - that solved the problem. However it does seem a bit unusual that I have my subclass types defined with a discriminator, am trying to load a collection of a specific type and the discriminator is not applied.

Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.