A have a simple Criteria generator that traverses a network of objects rooted in single object implementing an Interface I call QueryObject. The basic algorithm is:
1) Add Criterion for all basic properties.
2) Add Criteria for a non-null composite objects; recurse to 1
3) Add Criteria for all non-null collections recurse to 1
It works great in a captive environment! In the real world it falls down. The problem is that in step 2 and 3 I "add" a Criteria without knowing if that Criteria will have any Criterion. We are using a Spring/JSP front in which likes to have an empty network of objects to bind to, thus the QueryMachine is being passed an QueryObject with composite objects and collections of composite objects which generate no Criterion.
This results an what is basically a "where exists" outer join. So my questions are:
1) Was the ability to add an outer join Criteria added to Hibernate and will that solve my problem?
2) Alternatively, can I create a subordinate Criteria and add them to other Criteria after determining if subordinate Criteria has any Criterion. Something like myCriteria.add(subordinateCriteria)
3) Other suggestions?
|