Projection投影

你说的曾经没有我的故事 提交于 2020-03-15 01:47:57

解释一

Projection means choosing which columns (or expressions) the query shall return.

Selection means which rows are to be returned.

if the query is

select a, b, c from foobar where x=3;

then "a, b, c" is the projection part, "where x=3" the selection part.

解释二

In terms of query it is:

SELECT *PROJECTION* FROM Table

*PROJECTION* is expression for data transformation.

Example:

SELECT * FROM ORDER

In Hibernate, the Criteria equivalent would be:

List orders = session.createCriteria(Order.class).list();

No projection here, we take data without transformation. If we want one:

SELECT NAME FROM PRODUCT

Here, the Projection class comes into play. The above query can be rewritten into a Criteria query as:

List products=session.createCriteria(Product.class)
     .setProjection(Projection.property("name"))
     .list();

So we project all rows to single item: name field.

There are other projections: Projection.rowCount() for example (for COUNT(*))

参考资料

  1. What are projection and selection?
  2. What is a Projection in NHibernate?
  3. Hibernate 4.3.11 Final - Relational Persistence for Idiomatic Java
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!