-->
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.  [ 2 posts ] 
Author Message
 Post subject: class-level filters don't work?
PostPosted: Tue Apr 25, 2006 11:00 am 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Hello,

Here is my problem:

Child class:

<hibernate-mapping>
<class name="child">
<id name="childId" type="long"> <column name="CHILD_ID"/> </id>
...
<filter name="childIdFilter" condition=":childId=CHILD_ID"/>
</class>
<filter-def name="childIdFilter">
<filter-param name="childId" type="long"/>
</filter-def>
</hibernate-mapping>

Parent class:

<hibernate-mapping>
<class name="parent">
<id name="parentId" type="long"> <column name="PARENT_ID"/> </id>
<set name="children" inverse="true">
<key> <column name="PARENT_ID"/> </key>
<one-to-many class="child" />
</set>
</class>
</hibernate-mapping>

When I leave the mapping like this, child records are not filtered when I load parent class (even though childIdFilter is enabled and parameter is set). On the other hand, when I remove filter definition from child and put it inside the <set> tag in parent, child records are being filtered:

<set name="children" inverse="true">
<key> <column name="PARENT_ID"/> </key>
<one-to-many class="child" />
<filter name="childIdFilter" condition=":childId=CHILD_ID"/>
</set>

I don't quite understand why this is so. Hibernate documentation says that filters can be declared at both levels, and there is no mention that one works differently from the other.
If anybody knows if I could use class-level (as opposed to set-level) filters, please tell me how to go about it.

Also, I have a small side-question: is it possible to use filters to prevent many-to-one objects (linked to parent class) from being loaded? I'm trying to find a way to limit the amount of data being loaded for the parent class without permanently changing the hibernate mapping.

Thank you!

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 1:31 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Class level filters DO work, if you are loading the child itself. You're right that it doesn't filter on the one to many level and that you have to the filter at the collection level as well.


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