Replacing MyBatis with MyBatis-Plus: Troubleshooting LocalDateTime Conversion Issues and Version Compatibility
This article details the migration from MyBatis to MyBatis-Plus in a Java project, explains the LocalDateTime conversion exception caused by MyBatis 3.5.1 and an outdated mysql‑connector‑java driver, and outlines the step‑by‑step fixes including driver upgrades and lessons learned from a separate file‑generation bug.
Background
An existing project uses MySQL 5.7.36, MyBatis 3.5.0, and mysql‑connector‑java 5.1.26. A new developer finds MyBatis cumbersome and decides to replace it with MyBatis‑Plus 3.1.1 while keeping other component versions unchanged.
Migration Steps and Initial Failure
A demo table tbl_order is created and populated with two rows. When running com.qsl.OrderTest#orderListAllTest , a TransientDataAccessResourceException occurs, indicating "Conversion not supported for type java.time.LocalDateTime".
org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column 'pay_time' from result set. Cause: java.sql.SQLException: Conversion not supported for type java.time.LocalDateTime ...The stack trace shows the failure originates from the JDBC driver, not MyBatis‑Plus itself.
Root Cause Analysis
MyBatis 3.5.1 stopped handling LocalDateTime , LocalDate , and LocalTime conversions, delegating them to the JDBC driver. The used driver version (5.1.26) does not support these Java 8 time types, leading to the exception.
Upgrading mysql‑connector‑java to 5.1.37 adds support for the missing types, and the test runs successfully.
Further Issues and Fixes
After a version upgrade, inserting a record with a NULL pay_time triggers another exception. Investigating the driver source confirms that getObject throws a conversion error when the type is unsupported.
Upgrading the driver further to 5.1.42 resolves the null‑handling problem.
Additional Case: File‑Generation Validation Bug
The author shares a separate incident where a validation bug in a file‑generation service was “fixed” but later caused production failures due to hidden dirty data. The story highlights the risk of changing code without comprehensive testing.
Conclusion
Component upgrades can have far‑reaching effects; careful version compatibility checks and thorough testing are essential. When migrating MyBatis to MyBatis‑Plus, ensure the JDBC driver supports Java 8 time types, and avoid unnecessary changes unless fully validated.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.