What are Projections in Hibernate?

Answered

What are Projections in Hibernate?

Ninja Asked on 18th September 2018 in Hibernate.
Add Comment
1 Answer(s)
Best answer

Projections API is introduced as part of Criteria API which is used to load partial object from database and to find the result of aggregate functions. Projection is an interface and Projections class is similar to Restrictions class and provides a set of static factory methods for producing Projection instances.

.....
Criteria cr = session.createCriteria(Student.class);
// To get total row count
cr.setProjection(Projections.rowCount());
// To get distinct count of a property
cr.setProjection(Projections.countDistinct("studentName"));
.....

Ninja Answered on 18th September 2018.
Add Comment