Replacing MyBatis with MyBatis‑Plus Can Trigger LocalDateTime Conversion Errors

A newcomer swapped MyBatis for MyBatis‑Plus in an old Java project, which caused a runtime exception about unsupported java.time.LocalDateTime conversion; the root cause was a MyBatis version change and an outdated MySQL JDBC driver, fixed by upgrading the driver.

Top Architect
Top Architect
Top Architect
Replacing MyBatis with MyBatis‑Plus Can Trigger LocalDateTime Conversion Errors

Background

The legacy project used MySQL 5.7, MyBatis 3.5.0 and mysql‑connector‑java 5.1.26. A new developer found MyBatis verbose and decided to replace it with MyBatis‑Plus 3.1.1 while keeping all other components unchanged.

Demo Setup

A simple table tbl_order was created and populated with two rows. The test class com.qsl.OrderTest#orderListAllTest was executed to verify the migration.

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

Running the test produced the following exception:

Conversion not supported for type java.time.LocalDateTime
error screenshot
error screenshot

Root‑Cause Analysis

The stack trace showed that the failure originated from mysql‑connector‑java. The driver version 5.1.26 does not support the JDBC conversion of java.time.LocalDateTime, LocalDate, or LocalTime.

MyBatis 3.5.0 performed the conversion internally, but starting with MyBatis 3.5.1 the conversion was removed and delegated to the JDBC driver. MyBatis‑Plus depends on MyBatis 3.5.1, so after the replacement the conversion responsibility shifted to the driver, exposing the incompatibility.

Documentation of the driver shows that support for these Java 8 time types was added in version 5.1.37:

driver support list
driver support list

Fix

Upgrading mysql‑connector‑java to 5.1.37 (or later 5.1.42) restores support for the time types. After the upgrade the same test runs without exception and returns correct query results.

successful run
successful run

Lessons Learned

Component upgrades can change hidden behaviours; a seemingly harmless ORM replacement introduced a version mismatch that broke time‑type handling. When modifying legacy code, comprehensive testing—including version compatibility checks for JDBC drivers and framework internals—is essential to avoid production incidents.

JavaMySQLMyBatisJDBCMyBatis-PlusVersion Compatibility
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.