Replacing MyBatis with MyBatis-Plus: Debugging LocalDateTime Conversion Errors and MySQL Connector Upgrades
The article walks through migrating an old MySQL‑5.7 project from MyBatis 3.5.0 to MyBatis‑Plus 3.1.1, diagnosing a LocalDateTime conversion exception caused by an outdated mysql‑connector‑java driver, and resolves it by upgrading the driver version, highlighting the need for careful component compatibility checks.
Background: an old project uses MySQL 5.7, 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, keeping the same MySQL connector version.
Running the test com.qsl.OrderTest#orderListAllTest throws an exception “Conversion not supported for type java.time.LocalDateTime”. The stack trace shows the cause is that mysql‑connector‑java 5.1.26 does not support LocalDateTime, and MyBatis 3.5.1 (used internally by MyBatis‑Plus) stopped handling this conversion.
Investigation of the MyBatis release notes confirms that MyBatis 3.5.0 performed the LocalDateTime conversion, while 3.5.1 delegated it to the JDBC driver, which lacked support until version 5.1.37.
Solution: upgrade mysql‑connector‑java to 5.1.37 (or later, e.g., 5.1.42) and re‑run the test. The exception disappears and query results are correct.
The article also shows how to reproduce the issue with an INSERT statement:
INSERT INTO tbl_order VALUES (3, 'asdfgh', NULL, '2024-02-21 20:01:31.111', '2024-02-21 20:02:56.764');
After fixing the driver version, the MyBatis‑Plus migration works smoothly, illustrating the importance of checking transitive library compatibility when upgrading components.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.