In this section, you will learn about the hibernate projection with an example.
Projection Interface: This is an interface that extends the Serializable. An object-oriented representation of a query result set projection in a Criteria query. Built-in projection types are provided by the Projections factory class. The Projection interface might be implemented by application classes that define custom projections.
The following example to count the total number of rows and distinct rows to use the Projections.rowCount() and Projections.countDistinct() method.
Table Name: Insurance
Here is the code of program:
|log4j:WARN No appenders
could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select count(*) as y0_ from insurance this_
No. of rows: 
Hibernate: select distinct count(distinct this_.insurance_name) as y0_ from insurance this_
Distinct Count: 
Posted on: March 10, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles