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?
我正在开发一个基于Struts2 Framework的Web应用程序,用于实现MVC,Hibernate3用于通过DAO访问数据库,以及DTO用于映射数据库中的关系对象。在Hibernate上下文中,我想知道Criteria Clases用于进行复杂查询的范围,以及是否还有其他选项来执行此类任务?
Thanks.
1 个解决方案
#1
3
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).
通过“覆盖”,我假设你的意思是复杂的,与SQL相关的查询的域,可以通过链接方法调用通过特定的Criteria对象构建(如此处所讨论的)。
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 Criteria
object in the expected ways.
根据我的经验,可以通过以预期方式改变Criteria对象来执行依赖于结果过滤,排序,投影,分组,逻辑连接或析取语句或子查询的大多数常见任务。
As an alternative, you can use Session.createSQLQuery
to construct a raw SQL query, then Query.list
or Query.executeUpdate
to execute it. For example:
作为替代方案,您可以使用Session.createSQLQuery构造原始SQL查询,然后使用Query.list或Query.executeUpdate来执行它。例如:
Sesion sess = getSession();
Query mySelect = sess.createSQLQuery("SELECT * from foo");
List<Entity> results = mySelect.list();
Query myUpdate = sess.createSQLQuery("DELETE * from foo where bar = \"boz\"");
int updateCount = myUpdate.executeUpdate();
Obviously, you'll want to extend from this naive example, but you get the idea.
显然,你会想要从这个天真的例子中扩展,但你明白了。
#1
3
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).
通过“覆盖”,我假设你的意思是复杂的,与SQL相关的查询的域,可以通过链接方法调用通过特定的Criteria对象构建(如此处所讨论的)。
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 Criteria
object in the expected ways.
根据我的经验,可以通过以预期方式改变Criteria对象来执行依赖于结果过滤,排序,投影,分组,逻辑连接或析取语句或子查询的大多数常见任务。
As an alternative, you can use Session.createSQLQuery
to construct a raw SQL query, then Query.list
or Query.executeUpdate
to execute it. For example:
作为替代方案,您可以使用Session.createSQLQuery构造原始SQL查询,然后使用Query.list或Query.executeUpdate来执行它。例如:
Sesion sess = getSession();
Query mySelect = sess.createSQLQuery("SELECT * from foo");
List<Entity> results = mySelect.list();
Query myUpdate = sess.createSQLQuery("DELETE * from foo where bar = \"boz\"");
int updateCount = myUpdate.executeUpdate();
Obviously, you'll want to extend from this naive example, but you get the idea.
显然,你会想要从这个天真的例子中扩展,但你明白了。