In the previous chapter, you saw how to use JDBC in Spring applications. Even though Spring goes a long way toward simplifying JDBC development, you will find that you still have a lot of code to write with JDBC.
One elegant solution to avoiding all this code is to use an object-relational mapping (ORM) tool, which maps the data rows and creates appropriate Java objects. In order for such mapping tools to access Java objects in a standardized fashion, they have to follow Java bean naming conventions. For example, the mapping tools can also set referenced objects that result from a join operation.
There are two basic types of ORM frameworks: those in which you can rely on the framework to generate the SQL statements entirely, or those in which you can take a slightly more manual approach and write the SQL statements yourself. The first case speeds up development, but sometimes the SQL code is not efficient enough. With the second approach, you write the SQL code yourself, making sure to select the correct columns that the ORM framework uses to create instances of the Java beans.
In this chapter, we are going to focus on implementing the data access layer of a Spring application using iBATIS. Specifically, we will cover the following:
Configuration: We discuss the various configuration files you need to successfully use iBATIS in the data layer of your application.
Mapping files: In this section, you learn how to create the mapping files and how iBATIS uses these files to perform the mapping of the selected rows to the properties of the domain objects.
CRUD operations: You learn how to implement the select, delete, and update operations using iBATIS. You learn how to implement select operations that represent all types of data relationships. Finally, we discuss how you can make sure that the insert operations are using the correct primary key values.