I'm totally newbie in java world, so after trying to build my first app. I've stuck with the problem of user-defined search queries.
I use hibernate as ORM + DAO pattern. Users need to be able to perform search in database using simple combination of AND/OR predicates on objects's properties. I'd prefer not to fall into raw SQL but looking for something like "generic query language" wich I could convert into HQL, SQL or any kind of query language for particular ORM. Currently I'm playing with Predicates and Transformers from apache commons colections package, but can't see any simple way to convert predicate into other representation.
I've searched for some related pattern but could not find anything appropriate. Any help would be greatly appreciated.
using Hibernate, i suppose you´ve already seen the criteria-api ? using generic wrappers around this was our solution.
Thats is what I've tried to make first - to write generic wrapper around criteria API. But then I thought that I'm trying to reinvent the weel.
Thanks for reply.
Altought it's quite a hack, I use a Map<String,Object> filter object, and then I do
in my HibernateGenericDaoImpl<EId,EEntity> base class I have a method which decodes these and creates criteria-based queries.
The only reason is making my higher level logic independent from hibernate's api.