What Is iBATIS?

iBATIS represents the second of the two types of ORM tools mentioned in this chapter's introduction; it allows the developer to write the custom SQL code they need to populate the bean properties. iBATIS uses the same approach for data inserts and updates, which is very good news indeed. Sometimes you do not want to update the entire row (especially when the row is quite large); in a lot of cases, you just have one value to update. It also allows you to fully use your database's extensions to the standard SQL syntax. You may object to the fact that portability is an important feature of a J2EE application, but remember that in most cases, full database portability is often a phantom requirement (for further discussion of application design in Spring, check out 1]

iBATIS Versions

iBATIS has two distinct versions that have similar high-level functions, but the syntax of the configuration files is very different. Spring supports both versions of iBATIS, but iBATIS authors recommend that you develop new projects using the newer version. This is why we do not discuss iBATIS support for the older version.

Infrastructure and Configuration

Let's take a look at iBATIS configuration and mapping files. One central XML file contains references to mapping files that define the Java beans and all database operations. You can specify the location of this reference configuration file when you create an instance of the iBATIS beans in Spring.

The mapping files usually represent a single domain object and appropriate SQL code for persisting that object's data to the database. It is important that you realize that all mapping files are loaded at startup, and the mappings specified are validated against the actual objects. If a property is not present in the domain object, the bean creation fails.

Unlike stand-alone iBATIS applications, the only things you need to configure in a Spring iBATIS application are the reference file and the mapping files. The Spring iBATIS factory bean (org.springframework.orm.ibatis.SqlMapClientFactoryBean) takes care of loading the configuration files. Just like with JDBC, you should not create and manage database transactions manually in the iBATIS mapping files; always delegate the transaction management to Spring.

Figure 10-1 gives you a basic overview of the structure of the configuration files. We take a more detailed look at the recommended file locations and the exact content of the files in the next section.

image from book
Figure 10-1: Configuration files structure

[1] Some databases do not even support stored procedures



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net