Chapter 15. Advanced query options

This chapter explains all query options that you may consider optional or advanced. You'll need the first subject of this chapter, the Criteria query interface, whenever you create more complex queries programmatically. This API is much more convenient and elegant than programmatic generation of query strings for HQL and JPA QL. Unfortunately, it's also only available as a native Hibernate API; Java Persistence doesn't (yet) standardize a programmatic query interface.

Both Hibernate and Java Persistence support queries written in native SQL. You can embed SQL and stored procedure calls in your Java source code or externalize them to mapping metadata. Hibernate can execute your SQL and convert the resultset into more convenient objects, depending on your mapping.

Filtering of collections is a simple convenience feature of Hibernate—you won't use it often. It helps you to replace a more elaborate query with a simple API call and a query fragment, for example, if you want to obtain a subset of the objects in a collection.

Finally, we'll discuss the optional query result cache—we've already mentioned that it's not useful in all situations, so we'll take a closer look at the benefits of caching results of a query and when you'd ideally enable this feature.

Let's start with query by criteria and query by example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.179.153