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.