CHAPTER 9

image

Querying with Criteria and Example

In the previous chapter, you saw how to use Hibernate Query Language (HQL) and Java Persistence Query Language (JPA QL). HQL forces you to interact with the database using SQL-like syntax. You must have some knowledge of SQL to create complex queries, which makes it difficult to develop applications that use multicriteria queries.

With HQL and JPA QL, it’s easy to make mistakes with string concatenation and SQL syntax.1 Sometimes, errors occur simply because there is no space between two clauses in SQL. Because these errors are uncovered only at runtime, if you don’t have decent unit tests, you must ...

Get Hibernate Recipes: A Problem-Solution Approach, Second Edition now with O’Reilly online learning.

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