but what if theres just one collection?! (ie. the common case). Then
Hibernate would be adding an extra useless condition to the SQL, and
potentially slowing things down.


Aside: An interesting question that I need to ask a real DBA someday is:
"should Hibernate generate schemas with an index on the discriminator
column?"


>
> True, my example is breaking a single relational association into two
> object associations.  But there are use cases where that isn't the case,
> for example:
>
> Parent class Animal, subclass Cat, subclass Dog
>
> Class Household has a set of Cats and a set of Dogs
>
> If you tried to do this without adding the discriminator, Hibernate would
> load all of the cats and dogs both into the Cats list and the Dogs
> list.  To me it seems as though that isn't desired behavior.  Whenever you
> have a set of a discriminated subclass, it seems like Hibernate should be
> intelligent enough to only load the records that match the discriminator
> for that subclass.
>
> It's necessary whenever a parent could have links to subclasses of
> different types.
>
> Jenica Humphreys
> MountainView Software
>
> At 08:23 AM 8/29/2003 +1000, you wrote:
>>This is absolutely intended. Hibernate shouldn't go putting possibly
>>unnecessary conditions on the join of its own accord. This where
>> condition
>>is ONLY necessary if you have two different collections to discriminate
>>between. It is b/c you are breaking a *single* relational association
>> into
>>*two* object associations.
>>
>>
>> > Considering the mappings below, a note can belong to two different
>> types
>> > of
>> > owners.  This is accomplished using a discriminator value.
>> >
>> > Why is an additional where attribute required to apply the
>> discriminator
>> > when another class has a set of a discriminated subclass?
>> >
>> > This is my third mention of this issue.  No one seems to respond!  I
>> don't
>> > know if I'm being unclear.  I'll take a look at fixing it and
>> submitting a
>> > patch if it's not desired functionality, but I'm wondering if it works
>> > this
>> > way intentionally or if it is an oversight.
>> >
>> > Thanks for your help!
>> > Jenica Humphreys
>> > MountainView Software
>> >
>> >
>> > //----------------- CONTACT MAPPING --------------------------------
>> > <class name="Note" table="RM_Note" discriminator-value="99" >
>> > <id column="note_id" length="10" name="id" type="long"
>> > unsaved-value="null" >
>> >    <generator class="identity" />
>> > </id>
>> >
>> > <discriminator column="owner_type_cd" type="int" force="true"/>
>> >
>> > <property column="title_txt" length="50" name="titleTxt"
>> type="string"/>
>> > <property column="note_userid" length="10" name="userid"
>> type="string"/>
>> >
>> > <subclass name="ClaimNote" discriminator-value="0">
>> >    <many-to-one name="claim" column="owner_id"/>
>> > </subclass>
>> >
>> > <subclass name="ContactNote" discriminator-value="2">
>> >    <many-to-one name="contact" column="owner_id"/>
>> > </subclass>
>> >
>> > </class>
>> >
>> > //----------------- CONTACT MAPPING --------------------------------
>> > <class name="Contact" table="RM_CONTACT">
>> >    <id name="contactId" type="long" column="contact_id"
>> > unsaved-value="null">
>> >      <generator class="identity" />
>> >    </id>
>> >
>> >    <property name="firstName" column="first_name" length="15"
>> > type="string"/>
>> >    <property name="lastName" column="last_name" length="15"
>> > type="string"/>
>> >
>> >    <set name="notes" cascade="all" where="owner_type_cd=2" >
>> >      <key column="owner_id" />
>> >      <one-to-many class="ContactNote"/>
>> >    </set>
>> > </class>
>> >
>> > //------------------ CLAIM MAPPING ----------------------------------
>> > <class name="Claim" table="RM_CLAIM">
>> >    <id name="claimId" type="long" column="claim_id"
>> unsaved-value="null">
>> >      <generator class="identity" />
>> >    </id>
>> >
>> >    <property name="claimNbr" column="claim_nbr" length="15"
>> > type="string"/>
>> >    <property name="referenceNbr" column="ref_nbr" length="15"
>> > type="string"/>
>> >
>> >    <set name="notes" cascade="all" where="owner_type_cd=0" >
>> >      <key column="owner_id" />
>> >      <one-to-many class="ClaimNote"/>
>> >    </set>
>> > </class>
>> >
>> >
>> >
>> > -------------------------------------------------------
>> > This sf.net email is sponsored by:ThinkGeek
>> > Welcome to geek heaven.
>> > http://thinkgeek.com/sf
>> > _______________________________________________
>> > hibernate-devel mailing list
>> > [EMAIL PROTECTED]
>> > https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>> >
>>
>>
>>
>>-------------------------------------------------------
>>This sf.net email is sponsored by:ThinkGeek
>>Welcome to geek heaven.
>>http://thinkgeek.com/sf
>>_______________________________________________
>>hibernate-devel mailing list
>>[EMAIL PROTECTED]
>>https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>
>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to