Why Replacing MyBatis with MyBatis‑Plus Can Break Your DateTime Handling

A newcomer replaced MyBatis with MyBatis‑Plus in an old MySQL‑based project, encountered a "Conversion not supported for type java.time.LocalDateTime" error, traced it to MyBatis 3.5.1 dropping built‑in type handling and an outdated mysql‑connector‑java driver, and resolved it by upgrading the driver while also fixing a related validation bug that caused production failures.

Top Architect
Top Architect
Top Architect
Why Replacing MyBatis with MyBatis‑Plus Can Break Your DateTime Handling

Background

An existing project used MySQL 5.7.36, MyBatis 3.5.0 and mysql‑connector‑java 5.1.26. A new developer, eager to simplify code, decided to replace MyBatis with MyBatis‑Plus 3.1.1 while keeping other components unchanged.

Reproducing the Issue

A table tbl_order was created and populated with two rows. Running the test method com.qsl.OrderTest#orderListAllTest produced the exception:

Conversion not supported for type java.time.LocalDateTime

Exception stack trace
Exception stack trace

Root‑Cause Analysis

MyBatis 3.5.1 stopped handling conversions for LocalDateTime, LocalDate and LocalTime. The conversion responsibility was handed over to the JDBC driver. The driver version in use (mysql‑connector‑java 5.1.26) does not support these Java 8 time types, which caused the exception.

Driver support list
Driver support list

Support for the three time types was added starting with mysql‑connector‑java 5.1.37.

Fix

Upgrading the driver to 5.1.37 (or later, e.g., 5.1.42) restores the missing conversion support. After the upgrade, rerunning com.qsl.OrderTest#orderListAllTest no longer throws the exception and query results are correct.

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

Related Observations

The same problem appears in MyBatis‑Plus issue #1114. Using a different connection pool (e.g., Druid) can surface a different stack trace, but the underlying incompatibility remains the same.

Second Case: Validation Logic Bug

Another incident involved a file‑generation service where the original validation logic considered the check passed if *any* main file existed, whereas the business rule required *all* main files to be present. This bug allowed dirty data (e.g., a placeholder file name "abc_{yyyyMMdd}.txt") to slip through, causing a production failure when a dependent file could not be generated.

Original validation logic
Original validation logic

The validation was rewritten to require that every main file be generated before any dependent file proceeds, eliminating the inconsistency.

Optimized validation logic
Optimized validation logic

Lessons Learned

Component upgrades or seemingly harmless code changes can have far‑reaching effects. Avoid unnecessary modifications, and when changes are unavoidable, perform thorough testing to prevent regressions.

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.

DebuggingJavadatabaseMyBatisMyBatis-Plusversioning
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.