Get the online training

Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com

Web Service

Introduction and Overview of iBATIS

  • What is iBATIS?.
  • Hibernate Vs iBATIS
  • Setting up iBatis
  • Installing and configuring iBATIS
  • Example with Eclipse

Introduction and Overview of iBATIS

What is iBATIS?

  • iBATIS is a open source persistence frameworks.
  • iBATIS is just a data mapper framework.
  •  It maps fields in RDBMS tables to attributes in objects while Hibernate is an OR-mapping tool
  • It maps objects to relational database.
  • Sounds similar, but OR-mapping is higher level than data mapping.
  • iBATIS is very simple.
  • iBATIS is so simple, it is just about XML, SQL, and plain-old objects, nothing more than that.
  • iBatis is a java library that maps the results of a query on java objects (hence it’s also known as SqlMap)
  • dynamic queries, caching of queries, transactions and calling stored procedures.
  • Easy to Learn
  • iBatis works on top of JDBC, so if you have you’re database connection working with JDBC it works with iBatis.

Hibernate Vs iBATIS

  • Hibernate works very well if your data model is well in sync with object model, because ORM solutions like Hibernate map object to tables.
  • Hibernate is not the best solutions for data centric applications that only uses the stored-procedures to implement the business logic in database.
Use iBatis if
  • You want to create your own SQL's and are willing to maintain them
  • your environment is driven by relational data model
  • you have to work existing and complex schema's
Use Hibernate if
  • your environment is driven by object model and wants generates SQL automatically

Setting up iBatis


In this file you define the JDBC
 connection, it is also possible to use a JNDI or DBCP DataSource. 

Sample sqlMap-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"

 <settings cacheModelsEnabled="true" enhancementEnabled="true"
 lazyLoadingEnabled="true" maxRequests="32" maxSessions="10"
 maxTransactions="5" useStatementNamespaces="false" />
 <transactionManager type="JDBC">
 <dataSource type="SIMPLE">
 <property name="JDBC.Driver"
 value="oracle.jdbc.driver.OracleDriver" />
 <property name="JDBC.ConnectionURL"
 value="jdbc:oracle:thin:@" />
 <property name="JDBC.Username" value="scott" />
 <property name="JDBC.Password" value="tiger" />
 <sqlMap resource="Emp.xml" />
  • This file will act as the root configuration for our SQL Map implementation.
  • The configuration file is an XML file.
  • Within it we will configure properties, JDBC DataSources and SQL
  • Maps.
  • It gives you a nice convenient location to centrally configure your DataSource which can be any number of different implementations.
  • The framework can handle a number of DataSource implementations
  • including iBATIS SimpleDataSource, Jakarta DBCP (Commons), and any DataSource that can be lookedup via a JNDI context (e.g. from within an app server).


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
<sqlMap namespace="Emp">
 <select id="getEmployees" resultClass="nl.amis.Employee">
 SELECT empno as id, ename as name, job, 
 mgr as manager, hiredate as hireDate, 
 sal as salary, comm as commission, 
 deptno as department
 FROM emp

  • Every select query in iBatis is defined in the <select/> tag
  • The id attribute is the name you use in java and resultClass is the java class the query rows are mapped to
  • The text of the <select/> tag is the actual query (I put the CDATA tag around it because you sometimes use < and > and that could get you into trouble with xml).
  • The column names are renamed to the values of the java object (so we don’t have to rename job)
Installing and configuring iBATIS

  • Installing iBATIS is a quick and simple process.
  • It is a library, and not an application, there is no installation process.
  • To get iBATIS, You can either download a binary distribution
    and unzip it into a directory,.
  • The binary distribution of iBATIS is currently available at
  • Once you have a build of the distribution, you simply need to add the required
    JAR files to your application’s classpath
 ibatis-common-2.jar—Shared iBATIS classes1
 ibatis-sqlmap-2.jar—The iBATIS SQL mapping classes

Those two JAR files contain the most important iBATIS functionality and will be
enough for nearly any application that uses iBATIS