Why MyBatis‑Plus Migration Fails: LocalDateTime Conversion and Connector Version Issues
A legacy project using MySQL 5.7, MyBatis 3.5.0 and mysql‑connector‑java 5.1.26 encounters a "Conversion not supported for type java.time.LocalDateTime" error after switching to MyBatis‑Plus 3.1.1, which is traced to MyBatis 3.5.1 dropping built‑in LocalDateTime handling and the old connector not supporting the type, requiring an upgrade to mysql‑connector‑java 5.1.37 or later.
The original system was built on MySQL 5.7.36, MyBatis 3.5.0 and mysql‑connector‑java 5.1.26. A new developer found MyBatis cumbersome and decided to replace it with MyBatis‑Plus 3.1.1 while keeping the other components unchanged.
Initial Migration Attempt
A demo table tbl_order with two rows was created, and a simple MyBatis‑Plus demo was built to simulate the migration. Running the test method com.qsl.OrderTest#orderListAllTest produced an exception:
Conversion not supported for type java.time.LocalDateTimeThe stack trace highlighted that the java.time.LocalDateTime type could not be converted, and the culprit was identified as the JDBC driver: mysql‑connector‑java 5.1.26 does not support this type.
Root‑Cause Analysis
MyBatis 3.5.0 handled LocalDateTime internally, converting java.sql.Timestamp to the Java 8 time class. Starting with MyBatis 3.5.1, this handling was removed; conversion is delegated to the JDBC driver. Since the driver version in use (5.1.26) lacks support for LocalDateTime, the conversion fails.
Inspection of the driver’s supported types (via the driver’s documentation and a quick test) confirmed that LocalDateTime, LocalDate and LocalTime are absent until mysql‑connector‑java 5.1.37.
Fixing the Issue
Upgrading the JDBC driver to version 5.1.37 (or later) restores support for the missing types. After the upgrade, re‑running com.qsl.OrderTest#orderListAllTest succeeds and returns correct query results.
Further Complications
When the project later upgraded MyBatis to 3.5.1 (implicitly via a dependency change), the same error resurfaced because the newer MyBatis no longer performed the conversion. The solution remained the same: use a driver version that supports Java 8 time types, e.g., mysql‑connector‑java 5.1.42.
Lessons Learned
Component upgrades can have cascading effects; a change in one library may expose incompatibilities in another.
Always verify that the JDBC driver version matches the expectations of the ORM framework, especially regarding Java 8 date‑time support.
When troubleshooting, start from the stack trace, identify the failing component, and check its version compatibility.
In summary, the migration failure was caused by MyBatis 3.5.1 delegating LocalDateTime conversion to the JDBC driver, which in versions prior to 5.1.37 does not support the type. Updating the driver resolves the problem.
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.
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.
