-->
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: Collection and inheritance
PostPosted: Thu Aug 28, 2003 11:30 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Another question about collection.
2 tables
Property and Company.
Code:
<hibernate-mapping>
    <class
        name="com.clearview.feedback.db.language.MultiLanguageProperty"
        table="multilanguage_property"
        dynamic-update="false"
        dynamic-insert="false"
        mutable="true"
    >

        <id
            name="id"
            column="prop_id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="sequence">
                <param name="sequence">multi_lang_seq</param>
            </generator>
        </id>

        <discriminator
            column="disc"
            type="string"
        />
        .................
        .................
        .................
        <subclass
            name="com.clearview.feedback.db.language.CompanyProperty"
            dynamic-update="false"
            dynamic-insert="false"
            discriminator-value="comp"
        >

        </subclass>

    </class>

</hibernate-mapping>



Such code
Code:
Company newCompany = (Company) session.
          loadSingleObject(Company.class, companyId);
List properties = newCompany.getProperties();


is invoked such sql query

Code:
select multilan0_.prop_id as prop_id__, language1_.lang_id as lang_id0_, language1_.name as name0_, language1_.description as descript3_0_, multilan0_.prop_id as prop_id1_, multilan0_.lang_id as lang_id1_, multilan0_.name as name1_, multilan0_.value as value1_, multilan0_.description as descript6_1_, multilan0_.ref_id as ref_id1_ from multilanguage_property multilan0_ left outer join language language1_ on multilan0_.lang_id=language1_.lang_id where multilan0_.ref_id=?


As you can see this sql query selects all properties with id like company id, but it should select properties with id = company.id and disc = 'comp'

And when i invoke
Code:
session.delete(newCompany);


SQL query is
Code:
delete from multilanguage_property where prop_id=?


Again such situation...

What shoud i do to select and delete only CompanyProperty objects?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can add a where attribute to the collection mapping.


I absolutely STUBBORNLY insist that Hibernate should *not* use the discriminator when loading collections (not unless you explicitly specify that in the where attribute).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 3:21 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
You can add a where attribute to the collection mapping.


I absolutely STUBBORNLY insist that Hibernate should *not* use the discriminator when loading collections (not unless you explicitly specify that in the where attribute).


Do you think it's right way?
I declared CompanyProperty with disc = "comp" but i have to declare this disc again in collection. And in another collection and in another and etc....

My opinion is if we declare that collection contains CompanyCollection it should contain them and no dance with tambourine?


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.