The iBATIS Data Mapper framework is an open-source persistence framework that allows you to use your model objects with a relational database. In contrast to Hibernate, you write SQL, much like you would with JDBC. You do this in a very simple XML file, allowing abstraction of SQL from Java classes. iBATIS is not an O/R Mapper (ORM). Rather, it is a Data Mapper. In Martin's Fowler's Patterns of Enterprise Application Architecture, he describes two patterns: Data Mapper and Metadata Mapping. The difference is that ORMs (Metadata Mappers) map classes to tables; iBATIS (Data Mapper) maps inputs and outputs to an interface (for example, SQL interface to an RDBMS). An ORM solution works well when you have control of your database. A Data Mapper like iBATIS works well when the database is heavily normalized and you need to pull from several tables to populate an object.
The figure below shows iBATIS's architecture.
iBATIS is the name of a open-source project started by Clinton Begin in 2001. Clinton had a few products, but none of them gained much recognition until the .NET Pet Shop was released, claiming that .NET was superior to Java in developer productivity and performance. Microsoft published a paper claiming that .NET's version of Sun's PetStore was 10 times faster and 4 times more productive. Knowing this wasn't the case, Clinton responded with JPetStore 1.0 in July 2002. Not only did this application have fewer lines of code and a better design than its .NET counterpart, but Clinton implemented it over a few weeks in his spare time!
Clinton's goals while writing JPetStore were to argue the points of good design, code quality, and productivity. The original .NET Pet Shop had a horrible design with much of the business logic contained in stored procedures, whereas JPetStore had a clean and efficient persistence framework.
This framework quickly drew the attention of the open-source community. Today, iBATIS refers to the "iBATIS Database Layer," which consists of a DAO framework and a SQL Map framework. Spring supports the iBATIS SQL Maps by providing helper classes to easily configure and use them. Furthermore, the Spring project includes JPetStore as one of its sample applications, rewriting many of its pieces to use Spring features.
iBATIS is a "sleeper project" in the open-source community. Not many folks know about it, but those who do, really like it. iBATIS's license is Apache, which means you can use it freely as long as your end-user documentation states that your product contains software developed by the Apache Software Foundation. You can modify the code, but then you can no longer distribute it under the Apache name without permission.
iBATIS is an excellent persistence framework to use with existing or legacy databases. You can easily migrate a JDBC-based application to iBATIS (most of the work involves extracting the SQL out of Java classes and into Java files). Not only is iBATIS fast and efficient, but it doesn't hide SQL, which is one of the most powerful and oldest languages today. Using iBATIS's SQL Maps, developers write SQL in XML files and populates objects based on the results of those queries. Much like the Spring/Hibernate combination, iBATIS DAOs require very few lines of code in each method.
In my experience, I've found the following qualities to be true of iBATIS:
- Easy to learn
- Queries are extremely efficient
- Easy transition because of pre-existing SQL
- Just as fast (if not faster) than Hibernate
- Writing iBATIS DAOs is similar to writing Hibernate DAOs
The following is a blog post from the homepage of the iBATIS project.
iBATIS in Action Released!
(January 26, 2007) A book for iBATIS? No way! Yes way. The book is here. This is the first edition, targeting primarily the Java platform. But it's definitely useful for .NET and even Ruby users, even if only to understand the concepts and and ideas behind iBATIS. Everything else is just syntax. Some people may wonder if we're just trying to make money by selling documentation (sounds familiar to some no doubt). But trust us, writing technical books is NO way to make money! We did this for you, so you'd have a definitive guide to read from instead of wading through various internet resources. I think we're more worried about the Amazon.com comments than the sales... I (Clinton) really want to say what a fantastic experience it was to work with Brandon and Larry on this project. You guys did a fantastic job.