RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Wake Up to iBATIS, the Hibernate Alternative for Spring : Page 4

As great as Hibernate is, a lesser-known Java persistence solution called iBATIS actually may be a superior technology for your Spring development in certain situations. Find out which.


Spring + iBATIS Web Example

To demonstrate the integration between Spring and iBATIS, the example uses a simple Web-based contact database. This application is very barebones and incorporates several shortcuts to keep the focus on showing a simple, yet non-trivial integration between these two technologies.

Demonstration Data Model
The data model is very straightforward, consisting of three tables:
  • Person—Each contact within the application has a first name, last name, and unique ID that are maintained in this table.
  • Address—Contacts can have one or more physical addresses registered in this table and associated with the person's unique ID.
  • Email—Contacts can have one or more email addresses registered in this table and associated with the person's unique ID.

Demonstration Use Cases
The Spring/iBATIS contact database supports the following use cases:
  • Query physical addresses by matching contact first or last names in whole or in part
  • Query digital addresses by matching contact first or last names in whole or in part
  • Add new people to the database
  • Add new addresses for existing people in the database

In order to keep the demonstration simple and maintain brevity within the source code, the application leaves out the standard capabilities of editing/updating, deleting, and custom reporting on data.

Running the Application
In order to run the application, you need a JDK 1.4+ environment and a J2EE-compliant Web server (Tomcat, Resin, Jetty, etc.) that supports JDK 1.4+. All of the other libraries you need (Spring, iBATIS, JSTL, HSQLDB) are available in the downloadable source code at the bottom of the page. Take the following steps to use the source code:
  1. Unzip the downloadable archive somewhere on your machine.
  2. Take the WAR file (demo.war) from the root of that archive and deploy it to your J2EE server (for Tomcat, simply drop the WAR file into the webapps directory).
  3. Launch the database server by running the startDB.bat file located in the db directory.
  4. Start your J2EE server and verify that the server starts without errors.
  5. Open a Web browser and browse to the demo application running on your server (probably http://localhost:8080/demo or http://localhost/demo). Figure 3 shows the demo on Mozilla Firefox.

    Click to enlarge

    Figure 3. Demo Application on Mozilla Firefox

  6. Have fun!

Don't Overlook iBATIS

The Spring Framework provides an excellent backbone for loosely coupling components and even other frameworks together to provide technologists with maximum flexibility and reuse. Across the myriad of persistence layer options available in the marketplace today, many software engineers have overlooked iBATIS. After reading this article and exploring the demonstration application, you should now have a better appreciation for what iBATIS has to offer and when you would want to use it in your work. With its low barriers to entry, transparent utilization of SQL, cleanly divided separation of responsibilities, and elegant integration with Spring, the strengths of iBATIS within today's computing environment are self-evident.

Kyle Gabhart serves as the SOA Practice Lead for Web Age Solutions, a provider of technology education and mentoring. Since 2001 he has contributed extensively to the SOA/web services body of knowledge as an author, speaker, consultant, and open source contributor. Find Kyle on the Web at http://www.gabhart.com or reads his blog on SOA at SOAmatters.com.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date