I'm trying to filter out parts of a single-class recursive (Parent/Child) tree structure according to user's role. The complete tree is accessed ok usinga separate key field - bi-directional construction of the unfiltered tree works fine, in a single query. However, trying to filter out a subset of the nodes (and then manually evicting any orphans) does not work, because Hibernate eagerly loads the lazy nodes to which no access is intended.
Consider a public root and a public leaf, and a "secret" intermediate node between these. When I try to filter out the secret node, I find that it is automatically loaded by Hibernate, outside the filtered query. Yes, the node class is declared lazy, as well as the <set ...> side. Any help, anyone ? To work around, I had to map the parent_id as a property, basically resort to manual ORM.
Hibernate version:3.0b1
Mapping documents:
<hibernate-mapping>
<class
name="pkg.TreeNode"
table="TREE_NODE" lazy="true" proxy="pkg.TreeNode">
...
<set name="children" table="TREE_NODE" inverse="true" cascade="none" lazy="true">
<key column="PARENT_ID" />
<one-to-many class="pkg.TreeNode" />
</set>
<filter .../>
</class>
<filter-def...>
...
<filter-def>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
one select that retrieves a filtered list of TreeNodes. I only need the ones reachable from root. OK to return "orphans", but they are not used...
|