Chapter 17. Customizing SQL

 

In this chapter

  • Falling back to JDBC
  • Mapping SQL query results
  • Customizing CRUD operations
  • Calling stored procedures

In this chapter, we cover customizing and embedding SQL in a Hibernate application. SQL was created in the 1970s, but ANSI didn’t standardized it until 1986. Although each update of the SQL standard has seen new (and many controversial) features, every DBMS product that supports SQL does so in its own unique way. The burden of portability is again on the database application developers. This is where Hibernate helps: its built-in query languages produce SQL that depends on the configured database dialect. Dialects also help produce all other automatically generated SQL (for example, when Hibernate has to retrieve a collection on demand). With a simple dialect switch, you can run your application on a different DBMS. Hibernate generates all SQL statements for you, for all create, read, update, and delete (CRUD) operations.

Sometimes, though, you need more control than Hibernate and the Java Persistence API provide: you need to work at a lower level of abstraction. With Hibernate, you can write your own SQL statements:

17.1. Falling back to JDBC

 
 

17.2. Mapping SQL query results

 
 

17.2.1. Projection with SQL queries

 
 

17.2.2. Mapping to an entity class

 
 

17.2.3. Customizing result mappings

 
 

17.2.4. Externalizing native queries

 
 

17.3. Customizing CRUD operations

 
 
 

17.3.1. Enabling custom loaders

 
 

17.3.2. Customizing creation, updates, and deletion

 
 
 
 

17.3.3. Customizing collection operations

 
 

17.3.4. Eager fetching in custom loaders

 
 
 

17.4. Calling stored procedures

 
 
 

17.4.1. Returning a result set

 
 
 
 

17.4.2. Returning multiple results and update counts

 
 
 
 

17.4.3. Setting input and output parameters

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest