-->
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: Many-to-many is not aware of discriminators/subclassing?
PostPosted: Mon Oct 11, 2004 9:51 am 
Beginner
Beginner

Joined: Fri Mar 19, 2004 7:21 am
Posts: 20
Hi there,

I am pretty new to Hibernate so I may be going about the below completely the wrong way..

I have an Asset class that has two many-to-many relationships to a Keyword class as follows..

<set name="concernKeywords" table="asset_keyword">
<key column="asset_id" />
<many-to-many class="ConcernKeyword" column="keyword_id"/>
</set>

<set name="countryKeywords" table="asset_keyword">
<key column="asset_id" />
<many-to-many class="CountryKeyword" column="keyword_id"/>
</set>

And the Keyword class.

<class name="Keyword" table="keyword">
<id name="keywordId" column="keyword_id" type="java.lang.Integer">
<generator class="assigned"/>
</id>

<discriminator column="keyword_class" type="java.lang.String"/>

<property name="keyword" column="keyword" type="java.lang.String" not-null="false" />
<property name="keywordStatus" column="keyword_status" type="java.lang.String"
not-null="false" />

<subclass name="ConcernKeyword"
discriminator-value="CONCERN">
</subclass>

<subclass name="CountryKeyword"
discriminator-value="COUNTRY">
</subclass>
</class>

Note that the asset_keyword table is used to represent both many-to-many joins. I would have expected Hibernate to be able to use the discriminator of the Keyword class in the join when it fetches each of the two Set objects. However, this is not what happens. Hibernate loads all related concerns AND countrys into both sets. It does not put a necessary "where keyword.keyword_class='CONCERN'" clause into its query.

Is there a workaround for this or must I break the asset_keyword junction table into two junction tables?

I tried using <set where="keyword_class='CONCERN'" /> but this looks for asset_keyword.keyword_class which doesn't exist.


Regards,
Damon.


Top
 Profile  
 
 Post subject: Re: Many-to-many is not aware of discriminators/subclassing?
PostPosted: Mon Oct 18, 2004 3:34 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
damonrand wrote:
Hi there,

I am pretty new to Hibernate so I may be going about the below completely the wrong way..

I have an Asset class that has two many-to-many relationships to a Keyword class as follows..

<set name="concernKeywords" table="asset_keyword">
<key column="asset_id" />
<many-to-many class="ConcernKeyword" column="keyword_id"/>
</set>

<set name="countryKeywords" table="asset_keyword">
<key column="asset_id" />
<many-to-many class="CountryKeyword" column="keyword_id"/>
</set>

And the Keyword class.

<class name="Keyword" table="keyword">
<id name="keywordId" column="keyword_id" type="java.lang.Integer">
<generator class="assigned"/>
</id>

<discriminator column="keyword_class" type="java.lang.String"/>

<property name="keyword" column="keyword" type="java.lang.String" not-null="false" />
<property name="keywordStatus" column="keyword_status" type="java.lang.String"
not-null="false" />

<subclass name="ConcernKeyword"
discriminator-value="CONCERN">
</subclass>

<subclass name="CountryKeyword"
discriminator-value="COUNTRY">
</subclass>
</class>

Note that the asset_keyword table is used to represent both many-to-many joins. I would have expected Hibernate to be able to use the discriminator of the Keyword class in the join when it fetches each of the two Set objects. However, this is not what happens. Hibernate loads all related concerns AND countrys into both sets. It does not put a necessary "where keyword.keyword_class='CONCERN'" clause into its query.

Is there a workaround for this or must I break the asset_keyword junction table into two junction tables?

I tried using <set where="keyword_class='CONCERN'" /> but this looks for asset_keyword.keyword_class which doesn't exist.


Regards,
Damon.



You mean this did not work for you ?
Code:
    <set name="concernKeywords" table="asset_keyword" [b]where="keyword_class='CONCERN'"[/b]>
       <key column="asset_id" />
       <many-to-many class="ConcernKeyword" column="keyword_id"/>
    </set>

    <set name="countryKeywords" table="asset_keyword" [b]where="keyword_class='COUNTRY'"[/b]>
       <key column="asset_id" />
       <many-to-many class="CountryKeyword" column="keyword_id"/>
    </set>


_________________
Thanks
Sameet


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 3:34 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
Please disregard the [b] tags in the code above....

_________________
Thanks
Sameet


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.