iBATIS DataMapper
Added by Joel Barciauskas, last edited by Joel Barciauskas on Aug 18, 2009  (view change)

This is meant to be a very rough first draft documenting common patterns in porting your iBatis configuration and mapping XML files from iBatis for Java 2 to iBatis for Java 3. I started working on porting and decided I needed to put it off for another time, and as such I haven't had time to test it. I cannot vouch for its correctness, but I thought I'd start this document for others to build on and correct as necessary.

New sqlMapConfig.xml DTD:

<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">

New sqlMap (*.map.xml) DTD:

<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD iBatis Mapper 3.0 //EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">


  • Root configuration tag <sqlMapConfig> is now <configuration>

Within the root configuration tag:

<settings x="y" foo="bar"/>

is now:

   <setting name="x" value="y"/>
   <setting name="foo" value="bar"/>

<typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration>

   <typeAlias ... />


  • The root element <sqlMap> is now <mapper>
  • The attribute parameterClass should be changed to parameterType
  • The attribute resultClass should be changed to resultType
  • The attribute class should be changed to type

The "groupBy" attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap

<resultMap id="productRM" type="product" groupBy="id">
   <result property="id" column="product_id"/>
   <result property="name" column="product_name"/>
   <result property="category" column="product_category"/>
   <result property="subProducts" resultMap="Products.subProductsRM"/>


<resultMap id="productRM" type="product" >
   <id property="id" column="product "/>
   <result property="name " column="product_name "/>
   <result property="category " column="product_category "/>
   <collection property="subProducts" resultMap="Products.subProductsRM"/>

Another example


<resultMap id="invoiceRM" type="invoice" extends="Invoice.abstractInvoiceRM">
   <result property="client" resultMap="Client.clientRM"/>
   <result property="accounts" column="invoiceNumber=INVOICE_NUMBER" select="Invoice.getAccountsSql"/>
   <result property="products" column="productGroup=PRODUCT_GROUP_ID" select="Invoice.getProductsSql"/>


<resultMap id="agreementDetailRM" type="agreement" extends="Agreement.agreementRM">
   <association property="client" resultMap="Agreement.clientRM"/>
   <collection property="accounts" column="agreementNumber=AGREEMENT_NUMBER" select="Agreement.getAccountsSql"/>
   <collection property="products" column="serviceGroupId=SERVICE_GROUP_ID" select="Agreement.getProductsSql"/>

In the above case, the id is defined in the parent result map.

Dynamic SQL

The most common dynamic SQL in my project is "isNotNull". Here is an example replacement regex:




<if test="$1 != null"

Note you will have to replace the closing tags </isNotNull> with </if> also.

Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators