I finally migrated my old system built with Spring + iBATIS to Spring + MyBatis3. I have tried migrating several times, but the number of SQL definition files exceeds 1000, and it takes too much time to manually migrate to the definition file for MyBatis. Official? tool did not work well, so I gave up. However, if I couldn't migrate to MyBatis, I couldn't upgrade Spring, so I thought it was awkward, so I created a definition file migration tool and completed the migration safely. I don't think there is much demand, but I decided to make it public so that it would be of some help to those who are in trouble somewhere.
Mybatis / ibatis2mybatis on GitHub seems to be the official tool, but I decided to make a migration tool because this tool could not migrate successfully in the following cases did. (I think there were others, but I forgot ...)
<dynamic>
, <isPropertyAvailable>
, <isNotPropertyAvailable>
tagsproperty
attribute is undefined in tags such as<isEqual>
,<isNotEqual>
,<iterate>
compile group: 'org.apache.ibatis', name: 'ibatis-sqlmap', version: '2.3.4.726'
compile group: 'org.mybatis', name: 'mybatis', version: '3.4.5'
compile group: 'org.mybatis', name: 'mybatis-spring', version: '1.3.1'
SqlMapClientFactoryBean
to use SqlSessionFactoryBean
.callSettersOnNulls
) to make it behave the same.returnInstanceForEmptyRow
) to get the same behavior. However, this change will also return empty instances when mapping nested results. In this case, iBATIS returned null, so in order to make it the same behavior, the migration tool described later sets notNullColumn
.<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" scope="singleton">
<property name="configLocations">
<list>
<value>classpath:/ibatis.xml</value>
</list>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:/mybatis/**/*.xml" />
<property name="configuration">
<bean class="org.apache.ibatis.session.Configuration">
<property name="callSettersOnNulls" value="true"/>
<property name="returnInstanceForEmptyRow" value="true"/>
</bean>
</property>
</bean>
SqlMapClientDaoSupport
to SqlSessionDaoSupport
getSqlMapClient ()
to getSqlSession ()
getSqlMapClient (). QueryForObject ()
to getSqlSession (). SelectOne ()
getSqlMapClient (). QueryForList ()
to getSqlSession (). SelectList ()
public class Dao extends SqlMapClientDaoSupport {
public Object find(String id) throws SQLException {
return getSqlMapClient().queryForObject(id);
}
public List findList(String id) throws SQLException {
return getSqlMapClient().queryForList(id);
}
}
public class Dao extends SqlSessionDaoSupport {
public Object find(String id) throws SQLException {
return getSqlSession().selectOne(id);
}
public List findList(String id) throws SQLException {
return getSqlSession().selectList(id);
}
}
I have created a tool for migrating iBATIS sqlMap files to MyBatis mapper files, so I will use it. You will need the JDK to run this tool, so please install it in advance.
GitHub - ogasada/ibatisToMyBatis3
$ git clone https://github.com/ogasada/ibatisToMyBatis3.git
systemProp.targetDir
in the gradle.properties
file$ ./gradlew convert
The migration tool may be inadequate as I limit it to the features I need. The program itself is not a big deal, so I think you can add functions if you change it appropriately.
Recommended Posts