I've been kicking around the Internet for a few days looking for a good way to handle a problem I'm having. I'm in the process of converting an older webapp from using a homegrown ORM to Hibernate. Things have been running fairly smoothly until I came across one fairly complex object graph. This graph is represented by about 2 dozen different objects, up to 8 layers deep in some places, and full of copious "to-many" relationships.
Mapping the graph for retrieval went fine; the problem is searching on the thing. If it matters, I have a Struts 2 action that takes a bunch of user input. My evil plan is to construct a Criteria from this and get the matching objects back. The portion I'm really having trouble with is that many of the values are represented as ranges (either between or greater/less than) between two different values stored on this object graph. Since the users may or may not choose to search on any of about 100 fields, it seems really tedious to just put their values on a simple map then check whether they and any necessary associated values exist in some sort of Hibernate backed DAO and create individual Criterion objects for each of these. Additionally, I have about 10 other objects of similar complexity that will eventually be rewritten.
So, this is my question: has anyone written a dynamic search on a large complex graph or does anyone have an idea as to how it might be done other than by specifying line-by-line the appropriate restrictions? I have had a few ideas, but they've been shot down by some others in my group for being excessively complex. As I stated, I have yet to find a "good" agreed upon way to do this, but it seems that it shouldn't be terribly uncommon.
|