I'm working on creating a Hibernate query engine that can create dynamic queries. Thus far I've been using the Criterion API to generate the queries. I'm having a hard time writing the engine in an OO fashion. I want to be able to create a new class for each association and have it pass back a fragment of the SQL call.
For example:
A person might own a home, a car, and a boat.
I want the user to be able to search "Return any person that has a blue home and a red boat" I have a searchTerm Map that looks like:
home.color = blue
boat.color = red
I'd want one singleton, for each criteria (boat,car,home), that I can pass in the entire map and it returns to me a Criteria object that I can use to build up my query. That's the theory. The problem I'm having is, in Hibernate, I need to create a criteria or alias to make associations between person and boat/house/car. In order to do that, I have to pass in the hibernate session. What I really want is to be able to return a detached-criteria and merge them all together. But it doesn't seem to be a way to do that.
In summary: A class that returns a criteria object that makes associations without the session object.
Any thoughts?
Thanks for reading!