ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
iBatis Tutorial

Contents
  1. iBatis Introduction

  2. Spring - iBatis Configuration

  3. Spring - iBatis Integration Example
  4. Resources

iBatis Tutorial

                     By Anand , developersBOOK.COM , 12/01/07

I've been playing around with Persistence frameworks lately, after been inspired by a Hibernate, which is a de facto standard is used in lot of places. While Hibernate is certainly an excellent technology, it is not always the right choice. In other words, Hibernate works very well if your data model is well in sync with object model, because ORM solutions like Hibernate map object to tables. However, let�s suppose data model is not in sync with object model, this is where the model starts breaking down. One size does not fit all. So this is where I like to use iBatis; as the alternative solution, iBatis maps results sets to objects, so no need to care about table structures. This works very well for stored procedures, works very well for reporting applications, etc,.You can find differences between iBatis & Hibernate  here.


iBatis Introduction


The first thing we need to know is:

What is iBatis ?

  • A JDBC Framework
    • Developers write SQL, iBATIS executes it using JDBC.
    • No more try/catch/finally/try/catch.
  • An SQL Mapper
    • Automatically maps object properties to prepared statement parameters.
    • Automatically maps result sets to objects.
    • Support for getting rid of N+1 queries.
  • A Transaction Manager
    • iBATIS will provide transaction management for database operations if no other transaction manager is available.
    • iBATIS will use external transaction management (Spring, EJB CMT, etc.) if available.
  • Great integration with Spring, but can also be used without Spring (the Spring folks were early supporters of iBATIS).

What isn't iBATIS ?

  • An ORM
    • Does not generate SQL
    • Does not have a proprietary query language
    • Does not know about object identity
    • Does not transparently persist objects
    • Does not build an object cache

Essentially, iBatis is a very lightweight persistence solution that gives you most of the semantics of an O/R Mapping toolkit, without all the drama. In other words ,iBATIS strives to ease the development of data-driven applications by abstracting the low-level details involved in database communication (loading a database driver, obtaining and managing connections, managing transaction semantics, etc.), as well as providing higher-level ORM capabilities (automated and configurable mapping of objects to SQL calls, data type conversion management, support for static queries as well as dynamic queries based upon an object's state, mapping of complex joins to complex object graphs, etc.). iBATIS simply maps JavaBeans to SQL statements using a very simple XML descriptor. Simplicity is the key advantage of iBATIS over other frameworks and object relational mapping tools.


Spring - iBATIS Configuration


 
HAVE YOUR SAY
At last a quick Ibatis tutorial that works.
Many thanks
Declanmagee, UK
Close
  • Social Web
  • Comments
Name: *
E-Mail: *
Message: *
Confirmation Code:
Enter code: *
(case sensitive)
 

Installing iBATIS is a quick and simple process. Because it is a library, and not an application, there is no installation process, but you do need to go through a few steps to use iBATIS in your application. You need to get the iBATIS library files. The entire iBATIS framework can be downloaded from iBATIS homepage. iBATIS is delivered in a single JAR file: ibatis-version.build.jar (as of now, ibatis-2.3.0.677.jar) and should be copied and made available at runtime via the application's class path.


Configuring the Environment:

Let�s see how to configure the iBatis-Spring environment. When working with Spring and iBATIS, you will have a minimum of three XML configuration files, and you will often have even more. It is important that you become familiar with these config files. So how do you make iBATIS available to your application? There are a couple of ways:

  1. Using Spring - iBATIS with a stand-alone application:

    You should place the ibatis-2.3.0.677.jar in the application's classpath. At minimum, you must define and place the following three configuration files in the classpath

    • Spring config - This file defines the database connection parameters, the location of the SQL Map config file, and one or more Spring beans for use within the application. ( applicationContext.xml).
    • SQL Map config - This file defines any iBATIS-specific configuration settings that you may need and declares the location for any SQL Map files that should be accessible through this config file. (SqlMapConfig.xml)
    • SQL Map(s) � One or more SQL Map files are declared in the SQL Map config and typically mapped to a single business entity within the application ,often represented by a single Java class (domainObject.xml).

  2. Using Spring - iBATIS with a web application

    Same as the above ,but just need one more xml (web.xml).

Now that we know the basic configuration steps,let's jump into example.


Next >>>> Spring - iBatis Integration Example

<<<<Previous | 1 2 3 |Next >>>>

  ALSO SEE :

About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2008 developersBOOK.COM. All rights reserved.