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.
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
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, ...