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