Weird situation that does not allow to implement DAO

I've been looking designs to access persistence services with hibernate.

Some elegant solution is to create concrete classes ( DAOs ) that implements some DBPersistenceService for example and interact with those DAOs using DTOs or not ( depends ).

My design is not like that, otherwise the query is hardcoded and is built dinamycally.

I mean, i select clause is hard-coded but the where clause is built dinamically depending on the values that I got from a SearchDTO. I could perform the search by name, lastName, age, etc. so depending on which field comes as a non null value I construct the where clause dinamically.

I think I should do a DAO implementation for hibernate, get the queries from the resources, set the parameters and that's it.

But how to do that if my where clause needs to be built dinamically depending on the values that I get from the DTO which I use to set the query parameters ?

Any design and solution ?

Regards.

Message was edited by:

jfreebsd

[1035 byte] By [jfreebsda] at [2007-10-3 2:12:57]
# 1
Just because the SQL is dynamic does not mean you cannot use a DAO. In terms of Hibernate specifically, you can use findByExample() to perform dynamic queries. Very easy to use and intuitive.- Saish
Saisha at 2007-7-14 19:11:48 > top of Java-index,Other Topics,Patterns & OO Design...