CHAPTER 10Advanced QueriesUsing Criteria

Hibernate provides three different ways to retrieve data. We have already discussed HQL and the use of native SQL queries—now we add criteria.

The Criteria Query API lets you build nested, structured query expressions in Java, providing a compile-time syntax-checking that is not possible with a query language like HQL or SQL. The Criteria API also includes query by example (QBE) functionality—this lets you supply example objects that contain the properties you would like to retrieve instead of having to spell the components of the query out step by step. It also includes projection and aggregation methods, including counts.

In this chapter, we explore the use of the Criteria API using the sample database ...

Get Beginning Hibernate: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.