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.
If there's just one collection, you still are asking for a collection of the subclass and you don't want the other subclasses. If your common case is asking for a set of the parent class, you can still do that and get the current functionality, no additional conditions slowing down the SQL.
In HQL, if you say select from SubclassA Hibernate always applies the discriminator. If you have a set of SubclassA in another class it should only have objects of SubclassA in it, which also requires that the discriminator be applied. If someone is going to put more than one type of object in the same table, and they ask for a set of only one of the subclasses, that's exactly what they should get - regardless of potential "useless" conditions. What is the point of ever having a set of a subclass otherwise? I may as well just always use a set of the parent class since that's what I'm going to get back anyway.
It seems to me that we're sacrificing accuracy for speed!
I'm not trying to cause trouble, since I do have a workaround for this issue. I just think it makes infinitely more sense that if I map a set of a subclass Hibernate would automatically filter what gets loaded into it. As I said before, if I can talk you into agreeing that it's a valid use case I will look into patching it myself. :)
Jenica Humphreys MountainView Software
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