I am attempting to use a <set> to map an entity's children in a tree which is expressed using "nested set" (left and right, worm walking the graph) notation. I believe that it would be relatively easy to do this if I were able to reference the containing object's properties from the where attribute. Something like this:
<class name="Category"
table="Categories">
<id name="id"
column="category_id"
type="long">
<set name="descendantCategories"
cascade="all-delete-orphan"
inverse="true"
order-by="category_left"
lazy="true"
where="category_left >= outer.category_left AND category_right <= outer.category_right">
<key column="category_id_root"
foreign-key="category_id_root" />
<one-to-many class="Category" />
</set>
<property name="left"
column="category_left" />
<property name="right"
column="category_right" />
<property name="name"
column="category_name" />
</class>
Notice the set definition for the "descendantCategories" property. The "where" attribute that I have quoted here is not valid because it attempts to access properties on the containing object (which I have prefixed with the pseudocode "outer." for clarity.) As far as I know, this is not possible with Hibernate 2.1.7. The net.sf.hibernate.sql.Template class merely scans the entire where clause and prepends the inner table name to all identifiers.
Is there something that I'm missing here? Is there another way to express what I am trying to express with the "outer." bit above? (I KNOW that "outer." is nonsense...I'm merely trying to illustrate my intent.) If not, does anybody know how difficult it would be to implement this? I believe that I could do it by making a few strategic changes to Template.renderWhereStringTemplate() and its callers. What pitfalls am I missing?
Thank you all for your time.
--Matt
|