Chapter 8. Queries

Hibernate supports a wide variety of options for retrieving objects from a database. These include the Hibernate Query Language (HQL), the Criteria API, and ordinary Structured Query Language (SQL).

In this chapter, we will take a look at each of these three retrieval mechanisms, and conclude with a mechanism for storing HQL and SQL queries directly in your *.hbm.xml mapping files.

HQL

The first thing you should know about HQL is that it is exclusively a query language. Unlike SQL, which offers statements of different forms for SELECT, UPDATE, DELETE, and INSERT, HQL is designed exclusively for retrieval. As a result, the syntax is most similar to the SELECT statement. There is no such thing as HQL for updating or inserting data, ...

Get Hibernate: A J2EE™ Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.