Why Replacing MyBatis with MyBatis‑Plus Can Break Production: A Deep Dive into Version Compatibility

This article walks through a real‑world case where swapping MyBatis for MyBatis‑Plus introduced a LocalDateTime conversion error, explains the root cause in MyBatis version changes and JDBC driver support, and shares subsequent bug fixes and lessons on cautious component upgrades.

Architect
Architect
Architect
Why Replacing MyBatis with MyBatis‑Plus Can Break Production: A Deep Dive into Version Compatibility

MyBatis to MyBatis‑Plus Migration

Background

An legacy project uses MySQL 5.7, MyBatis 3.5.0 and mysql‑connector‑java 5.1.26. A newly joined developer found MyBatis verbose and decided to replace it with MyBatis‑Plus 3.1.1 while keeping other components unchanged.

Initial Replacement and Failure

A demo table tbl_order with two rows was created and a simple MyBatis‑Plus demo (named play_it_safe) was built to simulate the replacement.

Running com.qsl.OrderTest#orderListAllTest raised the exception "Conversion not supported for type java.time.LocalDateTime".

The underlying reason was that mysql‑connector‑java 5.1.26 does not support conversion of java.time.LocalDateTime (or LocalDate, LocalTime) to SQL types.

Fixing the Connector Version

Upgrading mysql‑connector‑java to version 5.1.37 eliminated the exception and the query returned correct results.

Root‑Cause Analysis

MyBatis 3.5.0 internally handled LocalDateTimejava.sql.Timestamp conversion. Starting with MyBatis 3.5.1 this handling was removed and the conversion was delegated to the JDBC driver.

Since mysql‑connector‑java versions prior to 5.1.37 lack support for these types, the error appears after the migration to MyBatis‑Plus (which depends on MyBatis 3.5.1).

Further Issues – "Bug Not Meant to Fix"

After the connector upgrade, inserting a record with datetime values caused getTimestamp(columnIndex) to return NULL, leading to a NullPointerException during result processing.

Upgrading mysql‑connector‑java further to 5.1.42 resolved this secondary issue.

Another Incident – Validation Logic Bug

Later, an optimization changed the file‑generation validation logic. The original logic considered the check passed if any main file existed, which conflicted with the business rule that *all* main files must be generated.

The corrected logic required every main file to be present before generating auxiliary files.

However, after deployment a production error showed that a file name pattern abc_{yyyyMMdd}.txt had been stored in a numeric field, allowing the buggy validation to pass on dirty data and causing a later failure.

Takeaways

Component upgrades or code changes can have far‑reaching side effects; thorough testing is essential.

If a change is unavoidable, verify version compatibility and understand the underlying library behavior to avoid hidden regressions.

INSERT INTO `tbl_order` VALUES (3, 'asdfgh', NULL, '2024-02-21 20:01:31.111', '2024-02-21 20:02:56.764');
Author: 青石路 Source: https://www.cnblogs.com/youzhibing/p/18019399 Copyright notice: Content is for learning and research only; original copyright belongs to the author.
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.

debuggingjavaMyBatisORMmybatis-plusVersion Compatibility
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.