Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Name and version of the database you are using: 0racle 10
I am attempting to write queries against tree-structured data. Parent and child objects are of the same type (stored in the same table, and mapped through a getParents() collection. The parent-child relationship is many to many.
My need is to write an HQL query which returns a collection of these values which have all of a given set of parents, but possibly more parents than those in the set. So for a set
Code:
Set<Value> required;
I need to write HQL that efficiently returns all values which have at least all those required parents.
Currently, I am generating dynamic HQL by iterating over the set of required parents and generating an in clause for each of them, e.g. for a two-required-parent case
Code:
from Values v
where ? in elements(v.parents)
and ? in elements(v.parents)
with the two values from the required set passes as arguments. But this produces nasty repeated selects for the parents in the generated SQL, and seems wrong just on the esthetic level.
Is there a better way to do a collection-subset query like this?