SlideShare a Scribd company logo
1
Introduction to iBatis
Kunal Umrigar
2
3
Problems
 Tight integration of SQL code and Java code.
 Redundant JDBC code consumes a lot of development time.
 Is our DAO really a DAO?
4
Solutions?
5
Hibernate (ORM)
Object-Relational Mapping
??
6
Hibernate/Object-Relational Mapping
 Tools/techniques to store and retrieve objects from
a database
 From the code perspective it behaves like a
virtual object database
 A complete ORM solution provide:
 Basic CRUD functionality
 An Object-Oriented Query Facility
 Mapping Metadata support
 Transactional Capability
7
Hibernate pros and cons
Pros:
 No SQL coding required
 Database vendor independent
 Provides caching mechanisms
Cons:
 Requires learning of quite a lot of stuff
 Limits queries to HQL syntax
 Debugging and performance tuning is sometimes quite
complected
 Does not fit with legacy or complex Database.
8
An Introduction to Apache iBATIS
(i)nternet + A(batis)
SQL Mapping defined...
9
About iBATIS
 Open source framework that reduces the complexity to
read/save Java objects from a database (persistence)
 Decouples Java code from SQL
 Avoids the necessity to use JDBC
 It is NOT an object-relational mapper (such as
Hibernate)
 Simplifies the developer’s life ☺
10
iBatis Components
iBATIS usage is divided into two main components:
 SQLMaps
Permits to read/save Java objects into relational
DBMS without using JDBC and without mixing
Java and SQL code
 DAO <Spring framework DAO>
“Is an abstraction layer that hides the details of
your persistence solution and provides a common
API to the rest of your application”
Note: previous versions of iBatis had separate DAO component which is deprecated in the
latest version iBatis 3.
11
12
Sql Mapping
SQL Mapping Maps objects to SQL statements
 NOT Classes to Tables
Fully functional SQL via named statements
 NOT generated SQL (although that’s possible)
For example...
13
The Product Class
public class Product
{
private int id;
private String name;
private String description;
private BigDecimal cost;
private BigDecimal retail;
// ...getters/setters implied
}
14
The SQL
<select id=“getProduct" parameterClass=“int”
resultClass="examples.domain.Product">
SELECT
PRODUCT_ID as id,
NAME,
DESCRIPTION,
COST,
RETAIL,
FROM PRODUCT
WHERE PRODUCT_ID = #id#
</select>
15
<bean id="productDAO"
class="examples.domain.dao.ProductDAO">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
<property name="dataSource">
<ref bean="myDataSource" />
</property>
</bean>
The Spring DAO Bean
16
public class ProductDAOImpl extends SqlMapClientDaoSupport
implements
ProductDao
{
@SuppressWarnings("unchecked")
public List<Product> getAllProducts(int id)
{
List<Product> productList =
getSqlMapClientTemplate().queryForList(
"getProduct" , id );
return productList;
}
.....
The Product DAO Implementation
17
...
“WTF!! Do you mean we need to hand
code XML configurations?”
“Yeah!! That's true..”
...
18
JDBC
 Obtain the db Connection
 Create the statement
 Set the input parameters
 Execute the statement
 Create the result Collection
 For each row fetched:
 Create an object
 Set object’s properties using
row’s colums
 Add the object to the
Collection
 Release resources
 Close the Connection
 Return the Collection
IBATIS
Obtain the SqlMap object
Prepare complex parameters
(optional)
Invoke the query passing the
parameters
Return the result
JDBC-iBatis Comparison
19
5 Reasons to use iBatis
1. Works with any database that has a JDBC driver
(can re-use existing MySQL queries ) & You already
know SQL, why waste timelearning something else?
2. Supports Map, Collection, List and Primitive
Wrappers (Integer, String etc.)
3. Easy integration with Spring DAO.
4. Works well with legacy DB and complex relational
mappings between DB tables.
5. Supports complex object mappings (populating
lists, complex object models etc.), Transactions, Lazy
Loading or Join Mapping (1:1, 1:M, M:N), and caching.
20
- Full power of real SQL
- Works with complex, enterprise, ERP or
even poorly designed databases
- Fully supports composite keys and
complex relationships
- Complete stored procedure support
- JavaBeans support
- Primitive wrappers (Integer, String,
Date etc.)
- HashMap, List, Collection, and array[]
- XML text and DOM Support
- Null value translation
- Auto-mapping bean properties to
columns
- Dynamic SQL using conditional XML
tags
- Caching and dependency management
- Centralized data source configuration
- Local and global (JTA) transaction
support
- Small footprint 300k (minimum)
- Minimal dependencies (only common-
logging required)
- Spring DAO Templates available
iBATIS SQL Mapping Framework
21
Books:
 iBATIS In Action - Clinton Begin (Manning)
Links for reference:
 http://en.wikipedia.org/wiki/IBATIS
 http://ibatis.apache.org/onlinehelp.html
 http://www.javabeat.net/articles/52-spring-ibatis-integration-1.html
 http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp
 Using-iBatis-SQL-Maps-for-Java-Data-Access

More Related Content

PDF
Apache Con Us2007 Apachei Batis
 
PDF
Ibatis In Action 1st Edition Clinton Begin Brandon Goodin Larry Meadors
PPTX
SeaJUG May 2012 mybatis
PDF
iBATIS in Action 1st Edition Clinton Begin
PDF
I Batis In Action (非扫描Pdf完整版)
PPT
Dao benchmark
PPTX
Евгений Варфоломеев "Hibernate vs my batis vs jdbc: is there a silver bullet?"
PDF
Data access
Apache Con Us2007 Apachei Batis
 
Ibatis In Action 1st Edition Clinton Begin Brandon Goodin Larry Meadors
SeaJUG May 2012 mybatis
iBATIS in Action 1st Edition Clinton Begin
I Batis In Action (非扫描Pdf完整版)
Dao benchmark
Евгений Варфоломеев "Hibernate vs my batis vs jdbc: is there a silver bullet?"
Data access

Similar to fdocuments.in_introduction-to-ibatis.ppt (20)

PDF
Java persistence with my batis 3
PPTX
Hibernate in XPages
PDF
High performance database applications with pure query and ibm data studio.ba...
PDF
Free Hibernate Tutorial | VirtualNuggets
PPT
Hibernate
PDF
Java ibatis tutorial
PPT
2010 05-21, object-relational mapping using hibernate v2
PPT
Persistence hibernate
PPTX
Introduction to Ibatis by Rohit
PPT
PPTX
Module-3 for career and JFSD ppt for study.pptx
PPTX
Ups and downs of enterprise Java app in a research setting
PPT
Hibernate jj
PDF
Presentation for java data base connectivity
PDF
Hibernate In Action 1st Edition Christian Bauer Gavin King
PPTX
Advance java session 5
PDF
Hibernate 3
PDF
Apache iBatis (ApacheCon US 2007)
PDF
Understanding
Java persistence with my batis 3
Hibernate in XPages
High performance database applications with pure query and ibm data studio.ba...
Free Hibernate Tutorial | VirtualNuggets
Hibernate
Java ibatis tutorial
2010 05-21, object-relational mapping using hibernate v2
Persistence hibernate
Introduction to Ibatis by Rohit
Module-3 for career and JFSD ppt for study.pptx
Ups and downs of enterprise Java app in a research setting
Hibernate jj
Presentation for java data base connectivity
Hibernate In Action 1st Edition Christian Bauer Gavin King
Advance java session 5
Hibernate 3
Apache iBatis (ApacheCon US 2007)
Understanding

More from BruceLee275640 (7)

PPTX
Git_new.pptx
PDF
introductiontogitandgithub-120702044048-phpapp01.pdf
PPT
68837.ppt
PPT
Utility.ppt
PDF
springtraning-7024840-phpapp01.pdf
PPTX
java150929145120-lva1-app6892 (2).pptx
PPTX
life science.pptx
Git_new.pptx
introductiontogitandgithub-120702044048-phpapp01.pdf
68837.ppt
Utility.ppt
springtraning-7024840-phpapp01.pdf
java150929145120-lva1-app6892 (2).pptx
life science.pptx

Recently uploaded (20)

PDF
Bitcoin Layer August 2025: Power Laws of Bitcoin: The Core and Bubbles
PDF
how_to_earn_50k_monthly_investment_guide.pdf
PPTX
How best to drive Metrics, Ratios, and Key Performance Indicators
PPTX
introuction to banking- Types of Payment Methods
PDF
caregiving tools.pdf...........................
PDF
illuminati Uganda brotherhood agent in Kampala call 0756664682,0782561496
PDF
Dr Tran Quoc Bao the first Vietnamese speaker at GITEX DigiHealth Conference ...
PPTX
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
PDF
ECONOMICS AND ENTREPRENEURS LESSONSS AND
PDF
financing insitute rbi nabard adb imf world bank insurance and credit gurantee
PDF
Corporate Finance Fundamentals - Course Presentation.pdf
PPTX
4.5.1 Financial Governance_Appropriation & Finance.pptx
PPTX
Who’s winning the race to be the world’s first trillionaire.pptx
PDF
Why Ignoring Passive Income for Retirees Could Cost You Big.pdf
PPTX
Introduction to Customs (June 2025) v1.pptx
PPTX
Introduction to Managemeng Chapter 1..pptx
PPTX
kyc aml guideline a detailed pt onthat.pptx
PDF
NAPF_RESPONSE_TO_THE_PENSIONS_COMMISSION_8 _2_.pdf
PDF
final_dropping_the_baton_-_how_america_is_failing_to_use_russia_sanctions_and...
PDF
ECONOMICS AND ENTREPRENEURS LESSONSS AND
Bitcoin Layer August 2025: Power Laws of Bitcoin: The Core and Bubbles
how_to_earn_50k_monthly_investment_guide.pdf
How best to drive Metrics, Ratios, and Key Performance Indicators
introuction to banking- Types of Payment Methods
caregiving tools.pdf...........................
illuminati Uganda brotherhood agent in Kampala call 0756664682,0782561496
Dr Tran Quoc Bao the first Vietnamese speaker at GITEX DigiHealth Conference ...
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
ECONOMICS AND ENTREPRENEURS LESSONSS AND
financing insitute rbi nabard adb imf world bank insurance and credit gurantee
Corporate Finance Fundamentals - Course Presentation.pdf
4.5.1 Financial Governance_Appropriation & Finance.pptx
Who’s winning the race to be the world’s first trillionaire.pptx
Why Ignoring Passive Income for Retirees Could Cost You Big.pdf
Introduction to Customs (June 2025) v1.pptx
Introduction to Managemeng Chapter 1..pptx
kyc aml guideline a detailed pt onthat.pptx
NAPF_RESPONSE_TO_THE_PENSIONS_COMMISSION_8 _2_.pdf
final_dropping_the_baton_-_how_america_is_failing_to_use_russia_sanctions_and...
ECONOMICS AND ENTREPRENEURS LESSONSS AND

fdocuments.in_introduction-to-ibatis.ppt

  • 2. 2
  • 3. 3 Problems  Tight integration of SQL code and Java code.  Redundant JDBC code consumes a lot of development time.  Is our DAO really a DAO?
  • 6. 6 Hibernate/Object-Relational Mapping  Tools/techniques to store and retrieve objects from a database  From the code perspective it behaves like a virtual object database  A complete ORM solution provide:  Basic CRUD functionality  An Object-Oriented Query Facility  Mapping Metadata support  Transactional Capability
  • 7. 7 Hibernate pros and cons Pros:  No SQL coding required  Database vendor independent  Provides caching mechanisms Cons:  Requires learning of quite a lot of stuff  Limits queries to HQL syntax  Debugging and performance tuning is sometimes quite complected  Does not fit with legacy or complex Database.
  • 8. 8 An Introduction to Apache iBATIS (i)nternet + A(batis) SQL Mapping defined...
  • 9. 9 About iBATIS  Open source framework that reduces the complexity to read/save Java objects from a database (persistence)  Decouples Java code from SQL  Avoids the necessity to use JDBC  It is NOT an object-relational mapper (such as Hibernate)  Simplifies the developer’s life ☺
  • 10. 10 iBatis Components iBATIS usage is divided into two main components:  SQLMaps Permits to read/save Java objects into relational DBMS without using JDBC and without mixing Java and SQL code  DAO <Spring framework DAO> “Is an abstraction layer that hides the details of your persistence solution and provides a common API to the rest of your application” Note: previous versions of iBatis had separate DAO component which is deprecated in the latest version iBatis 3.
  • 11. 11
  • 12. 12 Sql Mapping SQL Mapping Maps objects to SQL statements  NOT Classes to Tables Fully functional SQL via named statements  NOT generated SQL (although that’s possible) For example...
  • 13. 13 The Product Class public class Product { private int id; private String name; private String description; private BigDecimal cost; private BigDecimal retail; // ...getters/setters implied }
  • 14. 14 The SQL <select id=“getProduct" parameterClass=“int” resultClass="examples.domain.Product"> SELECT PRODUCT_ID as id, NAME, DESCRIPTION, COST, RETAIL, FROM PRODUCT WHERE PRODUCT_ID = #id# </select>
  • 15. 15 <bean id="productDAO" class="examples.domain.dao.ProductDAO"> <property name="sqlMapClient"> <ref bean="sqlMapClient" /> </property> <property name="dataSource"> <ref bean="myDataSource" /> </property> </bean> The Spring DAO Bean
  • 16. 16 public class ProductDAOImpl extends SqlMapClientDaoSupport implements ProductDao { @SuppressWarnings("unchecked") public List<Product> getAllProducts(int id) { List<Product> productList = getSqlMapClientTemplate().queryForList( "getProduct" , id ); return productList; } ..... The Product DAO Implementation
  • 17. 17 ... “WTF!! Do you mean we need to hand code XML configurations?” “Yeah!! That's true..” ...
  • 18. 18 JDBC  Obtain the db Connection  Create the statement  Set the input parameters  Execute the statement  Create the result Collection  For each row fetched:  Create an object  Set object’s properties using row’s colums  Add the object to the Collection  Release resources  Close the Connection  Return the Collection IBATIS Obtain the SqlMap object Prepare complex parameters (optional) Invoke the query passing the parameters Return the result JDBC-iBatis Comparison
  • 19. 19 5 Reasons to use iBatis 1. Works with any database that has a JDBC driver (can re-use existing MySQL queries ) & You already know SQL, why waste timelearning something else? 2. Supports Map, Collection, List and Primitive Wrappers (Integer, String etc.) 3. Easy integration with Spring DAO. 4. Works well with legacy DB and complex relational mappings between DB tables. 5. Supports complex object mappings (populating lists, complex object models etc.), Transactions, Lazy Loading or Join Mapping (1:1, 1:M, M:N), and caching.
  • 20. 20 - Full power of real SQL - Works with complex, enterprise, ERP or even poorly designed databases - Fully supports composite keys and complex relationships - Complete stored procedure support - JavaBeans support - Primitive wrappers (Integer, String, Date etc.) - HashMap, List, Collection, and array[] - XML text and DOM Support - Null value translation - Auto-mapping bean properties to columns - Dynamic SQL using conditional XML tags - Caching and dependency management - Centralized data source configuration - Local and global (JTA) transaction support - Small footprint 300k (minimum) - Minimal dependencies (only common- logging required) - Spring DAO Templates available iBATIS SQL Mapping Framework
  • 21. 21 Books:  iBATIS In Action - Clinton Begin (Manning) Links for reference:  http://en.wikipedia.org/wiki/IBATIS  http://ibatis.apache.org/onlinehelp.html  http://www.javabeat.net/articles/52-spring-ibatis-integration-1.html  http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp  Using-iBatis-SQL-Maps-for-Java-Data-Access