Why Upgrading to MyBatis‑Plus Breaks LocalDateTime Mapping and How to Fix It

A newcomer replaced MyBatis with MyBatis‑Plus in an old MySQL‑based project, triggering a "Conversion not supported for type java.time.LocalDateTime" error, which was traced to MyBatis 3.5.1 dropping built‑in type handling and an outdated mysql‑connector‑java, and resolved by upgrading the connector and adjusting validation logic.

Top Architect
Top Architect
Top Architect
Why Upgrading to MyBatis‑Plus Breaks LocalDateTime Mapping and How to Fix It

A senior architect shares a real‑world case where a new developer upgraded an old project from MyBatis 3.5.0 to MyBatis‑Plus 3.1.1, keeping MySQL 5.7.36 and mysql‑connector‑java 5.1.26 unchanged. After the change, running com.qsl.OrderTest#orderListAllTest threw the exception "Conversion not supported for type java.time.LocalDateTime".

Background

The legacy system used MySQL 5.7.36, MyBatis 3.5.0, and mysql‑connector‑java 5.1.26. The newcomer felt MyBatis required too much boilerplate and switched to MyBatis‑Plus, but left all other component versions as‑is.

Root Cause Analysis

Stack traces showed the failure originated from the JDBC driver. MyBatis 3.5.1 stopped handling conversions for LocalDateTime, LocalDate, and LocalTime, delegating the work to the JDBC driver. The driver version 5.1.26 does not support these Java 8 time types, leading to the conversion error.

MySQL‑connector‑java started supporting these types from version 5.1.37 . Upgrading the connector to 5.1.37 (or later 5.1.42) resolves the exception.

Fix Implementation

After upgrading the connector, the same test runs without errors and returns correct query results.

INSERT INTO `tbl_order` VALUES (3, 'asdfgh', NULL, '2024-02-21 20:01:31.111', '2024-02-21 20:02:56.764');

Running com.qsl.OrderTest#orderListAllTest now succeeds.

Additional Insights

The issue mirrors MyBatis‑Plus issue #1114, which also points to the same conversion problem. The problem is independent of the connection pool (HikariCP vs Druid), but different pools may surface slightly different stack traces.

The article also describes a separate bug in a file‑generation validation routine where the logic incorrectly passed if *any* main file existed instead of requiring *all* main files. After correcting the validation, a hidden data inconsistency (a file name stored where an ID was expected) caused another failure, illustrating how a single change can expose latent bugs.

Conclusion

Component upgrades, especially in legacy codebases, can have far‑reaching side effects. Before changing libraries, verify compatibility of dependent components, and perform thorough testing to avoid cascading production incidents.

Error screenshot
Error screenshot
Table schema
Table schema
MyBatis version difference
MyBatis version difference
LocalDateTime handling change
LocalDateTime handling change
Connector version support matrix
Connector version support matrix
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingJavaConnectorMySQLMyBatisMyBatis-PlusLocalDateTime
Top Architect
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.