Tuesday, March 26, 2013


Conversion from iBatis 2 to MyBatis 3:



This page provides some information that is useful when migrating a project from iBatis 2 to MyBatis 3. It is probably not 100% complete.

Conversion Tool

There is a tool available in the downloads section that will help you to convert your iBATIS 2.x sqlmap files into MyBatis 3.x xml mapper files.
The tool is designed around an xslt transformation and some text replacements packaged in an ant task and tries to deliver a good starting point before the more complex work begins.

New DTDs

New sqlMapConfig.xml DTD:
New sqlMap (*.map.xml) DTD:
 

Configuration

  • Root configuration tag  is now 

Settings

Within the root configuration tag:
 x="y" foo="bar"/>
is now:

     name="x" value="y"/>
     name="foo" value="bar"/>
and
 useStatementNamespaces="true"/>
can be removed, since the use of namespaces has become mandatory.

 must be moved out of the  element to 

    
    ...
    

   

       
... />
   

 and 

 type="JDBC" commitRequired="false">
     type="your.package.CustomDataSourceFactory" />
is now:
 default="env">
     id="env">
         type="JDBC">
             name="commitRequired" value="false"/>
        
         type="your.package.CustomDataSourceFactory" />
    

 resource=... />
 resource=... />
 resource=... />
is now:

     resource=... />

Mapping

  • The root element  is now 
  • 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 columnIndex attribute does not exist anymore for the  tag
  • The groupBy attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap:
 id="productRM" class="product" groupBy="id">
     property="id" column="product_id"/>
     property="name" column="product_name"/>
     property="category" column="product_category"/>
     property="subProducts" resultMap="Products.subProductsRM"/>
New:
 id="productRM" type="product" >
     property="id" column="product "/>
     property="name " column="product_name "/>
     property="category " column="product_category "/>
     property="subProducts" resultMap="Products.subProductsRM"/>

Nested resultMaps

These should now be specified using the  tag.
 ...>
     property="client" resultMap="Client.clientRM"/>
    ...
is now:
 ...>
     property="client" resultMap="Client.clientRM"/>
    ...

Although this tag is deprecated, it can be used as in iBatis 2. However for versions up to 3.0.3 there is a bug when using type="map" and not specifying javaType for a parameter. This will result in
There is no getter for property named '...' in 'interface java.util.Map'    
This should be solved in MyBatis 3.0.4. For versions 3.0.3 and earlier the workaround is to explicitly specify javaType.

Inline parameters

#value#
is now:
#{value}

jdbcType changes

jdbcType="ORACLECURSOR"
is now:
jdbcType="CURSOR"
and
jdbcType="NUMBER"
is now:
jdbcType="NUMERIC"

Stored procedures

  • the  tag doesn't exist anymore. Use  or .
 id="getValues" parameterMap="getValuesPM">
    { ? = call pkgExample.getValues(p_id => ?) }
is now:
If you're calling an insert procedure that returns a value, you can use  instead of , but make sure to specifyuseCache="false" and flushCache="true". You'll also have to force a commit.
  • for stored procedures that return a cursor, there is a bug (see  issue 30 ) when using nested result maps (i.e. the output parameter's resultMap contains an  tag with the resultMap attribute). As long as the issue is not fixed, you have to specify the resultMap of the output parameter on the statement itself as well, or the nested resultMap will not be populated.

Caching

 id="myCache" type="LRU">
     hours="24"/>
     name="size" value="100" />
is now:
 flushInterval="86400000" eviction="LRU"/>
Note: you can omit eviction="LRU" since it is the default.
  • the  tag is replaced by the flushCache attribute for the statements and the cache will be used by all select statements by default.

Dynamic SQL

The most common dynamic SQL in my project is isNotNull. Here is an example replacement regex:
Pattern:
.*?property=\"(.*?)\">
Replacement:
 test="$1 != null">
Also common is the use of isEqual, you can replace this by a similar  tag.

Java code

SqlMapClient

  • This class doesn't exist anymore. Use SqlSessionFactory instead (see User Guide).

Custom type handler

  • Replace interface TypeHandlerCallback with TypeHandler. It has slightly different but similar methods.

Custom data source factory

Old interface:
com.ibatis.sqlmap.engine.datasource.DataSourceFactory
New interface:
org.apache.ibatis.datasource.DataSourceFactory
Replace method
public void initialize(Map properties)
with
public void setProperties(Properties props)

21 comments:

  1. Therefore, the characters must sell animal skins in order to get money for buying
    the weapons. So even at young ages and relatively low levels of the sport,
    goalies will have their helmets designed with various colors,
    prints and patterns, shapes or designs, and more. If you have ever tried to kid yourself that everything will be fine and glossed over certain issues because you wanted to avoid them, or did
    not know how to deal with them. It scored a decent 3208 marks in the PCMark04 benchmark.
    In doing so, it becomes the only potential choice for best gaming PC under 500 bucks in the desktop category.
    "What have you Googled lately. In 2005, the QI Group acquired a UK-based independent telecommunications provider with a strong background in providing advanced communications solutions and technology in the United Kingdom. In an effort to counter the lack of support from Microsoft, an SVG plug-in for Internet Explorer was developed and supported by Adobe. * You're realistic about what you expect from others. A Whole Lot of Exciting Options to Choose from Advanced car wash equipment use low-flow technology that drastically reduces drying times for carpets and upholstery.

    Review my website :: http://canadamomeh.ca/PauletteM

    ReplyDelete
  2. Wacom is probably the first stop for such a device, although Aiptek also make some of the most popular tablets
    on the market. For most young people, playing games on a
    computer, video game console, or handheld device is
    just a regular part of the day. You're punished more than and in excess of for generating faults in education and encouraged never ever to do it.

    my website :: http://atarsolfa.bloghi.com/2013/02/27/effortless-solutions-in-games-what-s-required.html

    ReplyDelete
  3. What's up friends, pleasant post and fastidious arguments commented at this place, I am in fact enjoying by these.

    Feel free to visit my blog post :: get money

    ReplyDelete
  4. It's very easy to find out any topic on web as compared to books, as I found this paragraph at this website.

    Review my web site :: twitter account

    ReplyDelete
  5. I really like what you guys are up too. This type of
    clever work and exposure! Keep up the awesome works guys I've added you guys to my own blogroll.

    Look into my page - Bret Fulker

    ReplyDelete
  6. Hi, i think that i saw you visited my site thus i came to return
    the choose?.I am attempting to find issues to improve my site!
    I suppose its ok to use some of your ideas!
    !

    Have a look at my web-site: p-tweets.com

    ReplyDelete
  7. Wow, this article is nice, my younger sister is analyzing these kinds of things,
    thus I am going to inform her.

    Feel free to visit my page - ミュウミュウ

    ReplyDelete
  8. Hiya very nice website!! Guy .. Beautiful .
    . Wonderful .. I will bookmark your web site and take the feeds also?
    I am satisfied to find a lot of helpful info here within the publish, we want develop
    more techniques in this regard, thank you for sharing.
    . . . . .

    Feel free to surf to my blog ... polo ralph lauren outlet

    ReplyDelete
  9. Howdy! I simply wish to give you a big thumbs up
    for the great information you have got here on this post.
    I am coming back to your site for more soon.

    My web-site; Polo Ralph Lauren Factory Store

    ReplyDelete
  10. Fastidious answers in return of this issue with real arguments and explaining the whole thing regarding that.


    Here is my web page ... Psn Code Generator

    ReplyDelete
  11. Exсellent рieces. Keep posting such κind оf infoгmаtion οn уour site.
    Im really іmpresseԁ bу yοur site.

    Thanκѕ foг shaгіng уour
    thοughtѕ аbout κeуworԁ.
    Rеgаrdѕ

    Heгe iѕ mу web page ... payday loans

    ReplyDelete
  12. Can I post your post to my wordpress weblog? I will add a one-way link
    to your forum. That’s one actually great post.


    Also visit my web site - trying to conceive tips

    ReplyDelete
  13. what is the mybatis equivalent for ibatis's queryForMap() and executeBatch()

    ReplyDelete
  14. What did change here? Do you really check before posting?

    These should now be specified using the tag.
    ...>
    property="client" resultMap="Client.clientRM"/>
    ...

    is now:
    ...>
    property="client" resultMap="Client.clientRM"/>
    ...

    ReplyDelete
  15. Could you please post the file again. File is no more accesible.

    ReplyDelete