解释一
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(*)
)
参考资料
- What are projection and selection?
- What is a Projection in NHibernate?
- Hibernate 4.3.11 Final - Relational Persistence for Idiomatic Java
来源:oschina
链接:https://my.oschina.net/jallenkwong/blog/3194956