-->
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.  [ 5 posts ] 
Author Message
 Post subject: Filtering many-to-many associations
PostPosted: Tue Jan 17, 2006 12:07 pm 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
I have a many-to-many association mapped through an association table:

<set lazy="true" table="risk_relation" name="relatedChildRisks">
<key column="risk_parent_fk"/>
<many-to-many class="Risk"
column="risk_child_fk"/>
</set>

I want to do filtering on the collection that is based on values in the Risk class, not the risk_relation (association) table. Conceptually, the mapping might look like this:


<set lazy="true" table="risk_relation" name="relatedChildRisks">
<key column="risk_parent_fk"/>
<many-to-many class="Risk"
column="risk_child_fk"
where="type = 'SOME_TYPE_VALUE'" />
</set>

but "where" is not valid in the many-to-many element. This makes sense to me in one-to-many associations, since the where attribute in the set element will be applied to the entity table because there is no intervening join table. But for many-to-many associations I can't figure out how to get to the values of the Risk table.

Is there a way to accomplish this in the mapping so that I don't have to do it programitcally?

Thanks in advance.

Hibernate version:3.0.4


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 1:21 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
How about
Code:
   
<set lazy="true" table="risk_relation" name="relatedChildRisks">
   <key column="risk_parent_fk"/>
   <many-to-many class="Risk"
                         column="risk_child_fk">
          <filter name="whatever" condition="type=SOME_TYPE_VALUE"/>
   </many-to-many>


'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 2:06 pm 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
Thanks very much for your reponse. I think that would work, but if I understand filters correctly, I would have to enable that filter on every session in which I wanted to load this association. That wouldn't be optimal for me, because I just want to specify a static filter that is always applied (it would cause data errors if someone forgot to enable it). But if there were some way to enable the filter declaratively, that would probably get me where I need to be.

Does that make sense?

rajasaur wrote:
How about
Code:
   
<set lazy="true" table="risk_relation" name="relatedChildRisks">
   <key column="risk_parent_fk"/>
   <many-to-many class="Risk"
                         column="risk_child_fk">
          <filter name="whatever" condition="type=SOME_TYPE_VALUE"/>
   </many-to-many>




Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 2:11 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
I see your point. But the DTD does have "where" as one of the attributes on the many-to-many element. Wouldnt that work as well? Your initial query said you cant use where. Why do you say so ?

From the DTD,
Code:
<!ELEMENT many-to-many (meta*,(column|formula)*,filter*)>
   <!ATTLIST many-to-many class CDATA #IMPLIED>
        <snip>
        <!ATTLIST many-to-many where CDATA #IMPLIED>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 2:22 pm 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
Well, actually I assumed that it would have a where attribute, but then my (old) xdoclet2 complained, so I looked at the reference doc:
http://www.hibernate.org/hib_docs/v3/re ... s-ofvalues

and did not see it there. But I have to confess that I didn't go all the way to the DTD. The where attribute is there.

Thanks for responding, sorry for using up your time without doing all my research.

Caleb

rajasaur wrote:
I see your point. But the DTD does have "where" as one of the attributes on the many-to-many element. Wouldnt that work as well? Your initial query said you cant use where. Why do you say so ?

From the DTD,
Code:
<!ELEMENT many-to-many (meta*,(column|formula)*,filter*)>
   <!ATTLIST many-to-many class CDATA #IMPLIED>
        <snip>
        <!ATTLIST many-to-many where CDATA #IMPLIED>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.