Why MyBatis‑Plus Upgrade Triggers LocalDateTime Errors and How to Fix Them
A legacy Java project using MySQL, MyBatis 3.5.0, and an old mysql‑connector‑java version encounters a Conversion not supported for java.time.LocalDateTime error after switching to MyBatis‑Plus, and the article walks through root‑cause analysis, version upgrades, and practical fixes.
Background
The legacy project runs on MySQL 5.7.36, MyBatis 3.5.0, and mysql‑connector‑java 5.1.26. A developer replaces MyBatis with MyBatis‑Plus 3.1.1 while leaving the JDBC driver version unchanged.
Reproducing the issue
A simple tbl_order table is created and populated with two rows. The demo code resides in the repository
https://gitee.com/youzhibing/qsl-project/tree/master/play_it_safe. Executing com.qsl.OrderTest#orderListAllTest throws:
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.LocalDateTimeThe stack trace points to a conversion failure for java.time.LocalDateTime.
Root‑cause analysis
MySQL‑Connector‑Java 5.1.26 does not support Java 8 time types. MyBatis 3.5.0 performed the conversion internally, but starting with MyBatis 3.5.1 the conversion is delegated to the JDBC driver, which then raises the exception.
Support for LocalDateTime, LocalDate and LocalTime was added in mysql‑connector‑java 5.1.37. The mismatch between MyBatis 3.5.1 (used indirectly by MyBatis‑Plus) and the old driver triggers the error.
Fix 1 – Upgrade mysql‑connector‑java to 5.1.37
Updating the driver to 5.1.37 eliminates the exception and the test returns the expected result.
Further issues after the first upgrade
Inserting a third record causes another failure because ResultSet.getTimestamp() returns NULL. Upgrading the driver further to 5.1.42 resolves this problem.
Additional investigation
The stack trace shows the failure originates from the JDBC driver, not from MyBatis‑Plus itself. An unrelated MyBatis‑Plus issue (issue‑1114) was discovered, but the root cause remains the driver’s lack of support for Java 8 time types. Different connection pools (e.g., Druid) may surface a different stack trace.
Lesson learned
When upgrading MyBatis to MyBatis‑Plus, ensure the JDBC driver version aligns with the MyBatis version’s handling of Java 8 time types. Comprehensive testing after any component upgrade is essential to avoid hidden incompatibilities.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
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.
