Why Replacing MyBatis with MyBatis‑Plus Can Break LocalDateTime Handling (and How to Fix It)

A developer upgraded an old Spring Boot project by swapping MyBatis for MyBatis‑Plus, ran into a Conversion not supported for java.time.LocalDateTime error, traced the root cause to MyBatis 3.5.1 delegating type conversion to an outdated mysql‑connector‑java, and resolved it by upgrading the connector and adjusting validation logic, illustrating the ripple effects of component upgrades.

macrozheng
macrozheng
macrozheng
Why Replacing MyBatis with MyBatis‑Plus Can Break LocalDateTime Handling (and How to Fix It)

MyBatis Replacement with MyBatis‑Plus

Background

An old project uses MySQL 5.7.36, MyBatis 3.5.0, and mysql‑connector‑java 5.1.26.

A new developer finds MyBatis cumbersome and decides to replace it with MyBatis‑Plus.

MyBatis‑Plus Replaces MyBatis

A demo table tbl_order is created and populated with two rows.

The demo uses MyBatis‑Plus version 3.1.1 while keeping the original mysql‑connector‑java version.

First Failure

Running com.qsl.OrderTest#orderListAllTest throws an exception:

Conversion not supported for type java.time.LocalDateTime

The error originates from mysql‑connector‑java, which does not support LocalDateTime in version 5.1.26.

Support starts from version 5.1.37.

Root‑Cause Analysis

MyBatis 3.5.1 stopped handling LocalDateTime, delegating conversion to the JDBC driver. The older driver lacks support, causing the failure.

MyBatis‑Plus itself is not at fault; the version change introduced the regression.

Storm Approaches

After upgrading the connector to 5.1.37, the original error disappears, but inserting a record with a NULL timestamp triggers another exception.

Further investigation shows the driver still lacks full handling; upgrading to 5.1.42 finally resolves the issue.

Related Issue

The same problem appears in MyBatis‑Plus issue #1114. The choice of connection pool (HikariCP vs Druid) can affect the observed behavior.

Fixing an Unrelated Bug

Background

A file generation system validates that all primary files are generated before creating dependent files.

Pre‑Optimization Validation

The original logic considered the validation passed if *any* primary file existed, which violated business rules.

Optimized Validation

The logic was corrected to require *all* primary files to be present.

Production Incident

After deployment, a dependent file failed because a primary file’s identifier stored a filename string (e.g., abc_{yyyyMMdd}.txt) instead of a numeric ID, exposing the previous validation bug.

Conclusion

Component upgrades or code changes can have far‑reaching effects; thorough testing and awareness of version‑specific behavior are essential to avoid cascading failures.

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.

JavamysqlORMmybatis-plus
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

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.