-->
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.  [ 1 post ] 
Author Message
 Post subject: How to define a filter on "one" end of many-to-one?
PostPosted: Thu Feb 09, 2012 2:50 am 
Newbie

Joined: Mon Aug 15, 2005 9:19 pm
Posts: 8
What is the best way to define a hibernate filter on class A to filter by some condition on class B where A-> B is many-to-one?

The only method I know is using a subselect (as below). But I don't like this method because it requires SQL. The idea of using SQL like this seems pretty flaky. How can I guarantee Hibernate won't break my SQL by messing with table aliases etc? Also, it gets messy if I have to traverse many relationships this way e.g. if I have A->B->C and I want to filter A on a property of C.

Is there a better way?

Code:
<class name="A>
    ....
    <many-to-one name="b" class="B"/>
    <filter name="bName" condition=":bName = (select name from b where a.b=b.id)"/>
</class>

<class name="B>
    ....
    <property name="name"/>
</class>


Thanks in advance,
David


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.