Hibernate 2.1b6, JDK 1.4.2_02
I have this situation:
- Parent has one-to-many Children
- Children objects/records are only viewable at a certain authorization level
My mapping for this association in Parent.hbm.xml is as follows:
Code:
<set
name="children"
lazy="true"
inverse="true">
<key column="PARENT_FK" />
<one-to-many class="domain.Child"/>
</set>
There are many queries on the Parent, where the Parent object is returned. Some queries just need the Parent, so I don't want to disable lazy loading. What I would like to do is filter the set of Child objects when getChildren() is called according to a variable that symbolizes the authorization level.
Specifically; the Child table has a Hibernate-mapped column that contains the authorization level, and the threads executing queries have a ThreadLocal object that contains the user's authorization level. These levels should match in order for the user to view the Child data.
Is it possible to put this into the mapping file? If so, how would I do it?
Code:
<set
name="children"
lazy="true"
inverse="true"
where="child.authlevel=:authlevel">
<key column="PARENT_FK" />
<one-to-many class="domain.Child"/>
</set>
Is this possible? If so, how would the ":authlevel" variable get set when code calls the parent.getChildren() method? Would a filter() method be more appropriate?
Any ideas or thoughts would be appreciated. Thanks,
--D