Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Improve persistence with Apache Derby and iBATIS, Part 1: Initial configuration, semantics, and a simple test

Daniel Wintschel is a regular guy who derives great excitement from solving business problems, streamlining processes, and writing all sorts of Java code. He loves coffee and is currently seeking development opportunities on a telecommuting basis from Singapore. You can contact the author at daniel@humandoing.net.

Summary:  The iBATIS database-mapping framework -- a popular Java™ framework for object-relational (OR) mapping -- is now an Apache open source project. This tutorial is the first in a three-part series demonstrating how to combine Apache Derby's power as a small-footprint embeddable database with iBATIS and use this combination to improve persistence in your database-driven Java applications. In Part 1, you learn about iBATIS's advantages as a persistence mechanism and focus on the iBATIS Data Mapper framework.

View more content in this series

Date:  24 Jan 2006
Level:  Intermediate PDF:  A4 and Letter (380 KB | 23 pages)Get Adobe® Reader®

Activity:  13777 views
Comments:  

Before you start

About this series

This tutorial is the first in a three-part series that introduces you to the iBATIS Data Mapper and Data Access Objects (DAO) frameworks and shows you how to use iBATIS with Apache Derby.

Part 1 discusses the concepts underlying iBATIS, including descriptions of the Data Mapper and DAO frameworks, and outlines the semantics and terminology that iBATIS uses. You look at some basic examples of how to configure Apache Derby with iBATIS and perform simple object-relational (OR) mapping using Data Mapper.

Part 2 focuses on the DAO framework, from the application layer down to the data-access and Derby database layers. You use the DAO framework with the Data Mapper framework through the JPetStore application. Using the DAO with the Data Mapper provides you with a clean and consistent way of accessing your application's underlying data structure.

Part 3 uses the Data Mapper to cover transaction handling, data caching, and creating dynamic SQL statements. It also takes a brief look at, and provides an example of, how to use the DAO framework without the Data Mapper framework to integrate it as a stand-alone framework within an application.


About this tutorial

As a developer, you've likely had the frequent responsibility of mapping your Java objects to relational database tables for persistence. Persistence is the ability to read objects from, write objects to, and delete objects from permanent storage -- a topic discussed ad infinitum in the Java community. This is where iBATIS comes in. It's a simple and powerful framework that does a great job of OR mapping, letting you solve business problems instead of mucking around with boilerplate code.

iBATIS consists of two frameworks, one of which -- the Data Mapper -- pertains specifically to OR mapping. The Data Mapper is this tutorial's main focus. You'll use the versatile Apache Derby as an embedded database for your persistence layer in the tutorial's example exercises.


Prerequisites

This tutorial assumes that you're comfortable working with basic SQL statements, that you understand basic XML semantics, and that you don't have any trouble reading through Java code. You need to know how to run Apache Ant to follow the tutorial's examples and create the database.


System requirements

To run the example code in this tutorial, perform the following steps:

  1. Download and install the following applications: You don't need to download iBATIS separately, because the necessary .jar files are included with the source code for this tutorial, which you download in step 3.
  1. Make sure that the environmental variables outlined in Table 1 are defined in your shell.
    Table 1. Setting the environmental variables
    Variable nameRequired setting
    DERBY_HOME Set to the root folder of your Derby installation.
    ANT_HOME Set to the root folder of your Ant installation.
    JAVA_HOME Set to the root folder of your Java installation.
    PATH Ensure that ANT_HOME/bin is in your path.

  2. Extract the supplied .zip file (see the Download section) to your preferred location. (This is the project root.) The project is laid out in Listing 1:

    Listing 1. Project layout
                                /iBATIS/
         /lib/        ' iBATIS JAR files to be included in the classpath
         /sql/        ' file containing DDL to create your database
         /src/        ' Java source code and iBATIS XML configs
         /build.xml   ' Ant build file
    
    

  3. Modify the /src/properties/database.properties file to specify where you would like Derby to create your database. I've set the url property in the database.properties file to be jdbc:derby:c:/temp/ibatis. See the database.properties file, shown in Listing 2, and change the path to include something appropriate for your file system.

    Listing 2. The database.properties file
                                ####################################
    # Database Connectivity Properties
    ####################################
    
    driver=org.apache.derby.jdbc.EmbeddedDriver
    url=jdbc:derby:c:/temp/ibatis
    username=
    password=
    

    Make sure that the value you specify is an existing empty directory. You can leave the username and password blank, as they are. If you're on a UNIX® or Linux® system, your path looks something like /tmp/ibatis, but you can create this directory wherever you want.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Information Management
ArticleID=133134
TutorialTitle=Improve persistence with Apache Derby and iBATIS, Part 1: Initial configuration, semantics, and a simple test
publish-date=01242006
author1-email=daniel@humandoing.net
author1-email-cc=troy@backstopmedia.com