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">
Configuration
- Root configuration tag <sqlMapConfig> is now <configuration>
Within the root configuration tag:
<settings x="y" foo="bar"/>
is now:
<settings>
<setting name="x" value="y"/>
<setting name="foo" value="bar"/>
</settings>
<typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration>
<configuration>
<settings>
...
</settings>
<typeAliases>
<typeAlias ... />
</typeAliases>
</configuration>
Mapping
- 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>
New:
<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"/> </resultMap>
Another example
Old:
<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>
New:
<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"/> </resultMap>
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:
Pattern:
<isNotNull.*?property=\"(.*?)\"
Replacement:
<if test="$1 != null"
Note you will have to replace the closing tags </isNotNull> with </if> also.
