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
- dtd restraint file is different.
- ibatis root element is
sqlMapConfig
, mybatis isconfiguration
- global setting properties is different.
- ibatis use
sqlMap
,mybatis usemappers
.
In mapping table
in ibatis namespace is not necessary, and has no meaning.
in mybatis it mean file’s corresponding DAO interface.ibatis has
resultMap
resultClass
two return typesresultMap
mean self define class,resultClass
nean java class.
mybatis union these tooresultType
.ibatis use
parameterClass
, mybatis useparameterType
parameter difference
mybatis useOGNL
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 | <select id="reduceGroupNumber" parameterMap="reduceParameters" statementType="CALLABLE"> |
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>
- implements machine from
SqlMapClient
toSqlSessionFactory
- class processor interface from
TypeHandlerCallback
toTypeHandler
DataSourceFactory
move toorg.apache.ibatis.datasource
package