Difference between ibatis and mybatis

ibatis3.x change name to mybatis.

Object relation mapping optimize

mybatis could package N+1 query problem, in <association> and <collection>
ibatis2 use nest query is a brute method, we can package in DAO or service as will.

But mybatis N+1 query not support paging query.
May be 1 to many is difficult to implements in framework,
and the number you want can’t be predict.

Mybatis implements interface binding

In ibatis2.x, we need to write
which xml mapping file is the DAO implements class binding.

In mybatis DAO interface’s name automatically binding
implements with xml file.

ps. although mybatis support annotation way config DAO,
but it loose flexibility, and invade code too much.

Configuration

In config

  1. dtd restraint file is different.
  2. ibatis root element is sqlMapConfig, mybatis is configuration
  3. global setting properties is different.
  4. ibatis use sqlMap,mybatis use mappers.

In mapping table

  1. in ibatis namespace is not necessary, and has no meaning.
    in mybatis it mean file’s corresponding DAO interface.

  2. ibatis has resultMap resultClass two return types
    resultMap mean self define class, resultClass nean java class.
    mybatis union these too resultType.

  3. ibatis use parameterClass, mybatis use parameterType

  4. parameter difference
    mybatis use OGNL expression.

    1
    2
    3
    4
    5
    # ibatis
    WHERE ID = #id:VARCHAR#

    # mybatis
    where ID = #{id,jdbcType=VARCHAR}

CLR

ibatis use <procedure> tag call precedure process.

1
2
3
4
5
6
7
8
9
<parameterMap id="reduceParameters" class="map">
<parameter property="id" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>
<parameter property="firstName" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
<parameter property="lastName" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
</parameterMap>

<procedure id="reduceGroupNumber" parameterMap="reduceParameters">
{call reduce_group_number (?, ?, ?)}
</procedure>

In mybatis <proccedure> has been removed,
<select> <insert> <update> replaced.

1
2
3
<select id="reduceGroupNumber" parameterMap="reduceParameters" statementType="CALLABLE">
{ ? = call reduce_group_number (?,?,?)}
</select>

statementType="CALLABLE" show it’s not a usual sql request.

Integration difference

ibatis:

1
2
3
4
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sqlMap-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

mybatis:

1
2
3
4
5
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:com/leon/core/config/mybatis-config.xml" />
<property name="mapperLocations" value="classpath*:com/leon/**/*Mapper.xml" />
</bean>

  1. implements machine from SqlMapClient to SqlSessionFactory
  2. class processor interface from TypeHandlerCallback to TypeHandler
  3. DataSourceFactory move to org.apache.ibatis.datasource package