I’m developing a web application based on Struts2 Framework for implementing the MVC, and Hibernate3 for accesing the database by means of DAOs, and DTOs for mapping the relational objects in the database. In the Hibernate context, I would like to know the reach of the Criteria Clases for making complex queries, and also if there is another option for doing such tasks?
Thanks.
By “reach,” I’m assuming you mean the domain of complex, SQL-related queries that can be constructed via chaining method calls through a specific Criteria object (as discussed here).
In my experience, most common tasks that rely on result filtering, ordering, projection, grouping, logical conjunctive or disjunctive statements, or subquerying can be carried out by mutating a
Criteriaobject in the expected ways.As an alternative, you can use
Session.createSQLQueryto construct a raw SQL query, thenQuery.listorQuery.executeUpdateto execute it. For example:Obviously, you’ll want to extend from this naive example, but you get the idea.