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
|