Chapter 14. Creating and executing queries

 

In this chapter

  • The basic query APIs
  • Creating and preparing queries
  • Optimizing query execution

If you’ve been using handwritten SQL for a number of years, you may be concerned that ORM will take away some of the expressiveness and flexibility you’re used to. This isn’t the case with Hibernate and Java Persistence.

With Hibernate’s and Java Persistence’s powerful query facilities, you can express almost everything you commonly (or even uncommonly) need to express in SQL, but in object-oriented terms—using classes and properties of classes. Moreover, you can always fall back to SQL strings and let Hibernate do the heavy lifting of handling the query result. For additional SQL resources, consult our reference section.

14.1. Creating queries

14.1.1. The JPA query interfaces

14.1.2. Typed query results

14.1.3. Hibernate’s query interfaces

14.2. Preparing queries

14.2.1. Protecting against SQL injection attacks

14.2.2. Binding named parameters

14.2.3. Using positional parameters

14.2.4. Paging through large result sets

14.3. Executing queries

sitemap