Chapter 16. Advanced query options

 

In this chapter

  • Transforming query results
  • Filtering collections
  • Query-by-criteria with the Hibernate API

This chapter explains query options that you may consider optional or advanced: transforming query results, filtering collections, and the Hibernate criteria query API. First, we discuss Hibernate’s ResultTransformer API, with which you can apply a result transformer to a query result to filter or marshal the result with your own code instead of Hibernate’s default behavior.

In previous chapters, we always advised you to be careful when mapping collections, because it’s rarely worth the effort. In this chapter, we introduce collection filters, a native Hibernate feature that makes persistent collections more valuable. Finally, we look at another proprietary Hibernate feature, the org.hibernate.Criteria query API, and some situations when you might prefer it to the standard JPA query-by-criteria.

Let’s start with the transformation of query results.

16.1. Transforming query results

16.1.1. Returning a list of lists

16.1.2. Returning a list of maps

16.1.3. Mapping aliases to bean properties

16.1.4. Writing a ResultTransformer

16.2. Filtering collections

16.3. The Hibernate criteria query API

16.3.1. Selection and ordering

16.3.2. Restriction

16.3.3. Projection and aggregation

16.3.4. Joins

16.3.5. Subselects

16.3.6. Example queries

16.4. Summary

sitemap