I am working on a CRM project that uses Spring MVC and Hibernate and I do not know what is the best place to use hibernate criteria. I want to use hibernate criteria because we have search capability on our presentation layer and users can search based on lots of various parameters in different ways. Sometimes we just need IDs, sometimes we need a subset of properties, sometimes we need to join multi tables, etc. So, building a structured criteria like hibernate's criteria instead of passing a list of parameters, orders, required parameters and search limits from presentation layer to data layer, can clean up the code. However, I know it is not correct to use hibernate in presentation layer as it is against MVC architecture. And I really don't think duplicating hibernate's criteria is the correct approach. I could think of 3 approaches:
Creating a dozen methods in business layer, one for each type of search requests, and calling each of these functions from presentation layer based on the situation. Each of these methods basically, do not do anything but passing the parameters to a corresponding DAO method which would create a SQL query (or criteria object) and retrieves the data from database. In this approach I would end up with hundreds of methods which do not do anything but passing the parameters to the DAO.
Creating a Class similar to Hibernate's Criteria class in presentation (or business layer). Then initiating this object with search parameters in presentation layer and passing it to DAO. DAO then creates a hibernate's criteria object based on this object. This approach involves duplicating hibernate's criteria class.
Initiating Hibernate's Criteria class in presentation layer and passing it to DAO to get the search result.
Can you please let me know which one is the best approach?
Thanks