[JAVA] Moved from iBATIS to MyBatis3

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.

I couldn't migrate successfully with the official tools

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 ...)

Migration work

Library changes

Change before

compile group: 'org.apache.ibatis', name: 'ibatis-sqlmap', version: '2.3.4.726'

After change

compile group: 'org.mybatis', name: 'mybatis', version: '3.4.5'
compile group: 'org.mybatis', name: 'mybatis-spring', version: '1.3.1'

Change settings

Change before

<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>

After change

<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>

Code changes

Change before

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);
    }
}

After change

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);
    }
}

Migrate sqlMap file to mapper file

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

  1. Get the project from GitHub $ git clone https://github.com/ogasada/ibatisToMyBatis3.git
  2. Modify the configuration file and specify the directory where the source sqlMap file is stored.
  1. Run the program and migrate to the mapper 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

Moved from iBATIS to MyBatis3
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Migrate from JUnit 4 to JUnit 5
From Java to Ruby !!
Try Spring Boot from 0 to 100.
Migration from Cobol to JAVA
Switch from slim3-gen to slim3-gen-jsr269
Moving from AWS to PaizaCloud
Suffering from MyBatis foreach error
New features from Java7 to Java8
Migrating from vargrant to docker
Connect from Java to PostgreSQL
Convert from ○ months to ○ years ○ months
Rewriting from applet to application
Change from SQLite3 to PostgreSQL
From Ineffective Java to Effective Java
How to migrate from JUnit4 to JUnit5
02. I made an API to connect to MySQL (MyBatis) from Spring Boot
How to push from Tarminal to GitHub
protocol buffeer migration from 2.x to 3.x
[Note] Download from S3, upload to S3
Stop resending from client to server
Ubuntu Desktop upgrade from 18.0.4 (?) To 20.04.1 (focal)
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
Migrate from on-premise Pukiwiki to esa.io \ (⁰⊖⁰) /
From introduction to use of ActiveHash
Switch from JSP + JSTL to Thymeleaf
Java to be involved from today
From Java to VB.NET-Writing Contrast Memo-
Introduction to Ruby (from other languages)
Java, interface to start from beginner
How to use MyBatis Mapper annotation
Change DB from SQLite to MySQL
Notes on migrating from CircleCI 1.0 to 2.0
Addicted to project imports from GitHub
Upgrade spring boot from 1.5 series to 2.0 series
We aim to update daily from 2021
From introduction to usage of byebug
Switch from Eclipse to VS Code
The road from JavaScript to Java
Memorandum Poem (updated from time to time)
[Java] Conversion from array to List
Update MySQL from 5.7 to 8.0 with Docker
How to change from HTML to Haml
Try to get data from database using MyBatis in Micronaut + Kotlin project