MyBatis version
3.5.14
Database vendor and version
sqlite 3.45.0 sqlite-jdbc 3.46.1.0
Test case or example project
example project: https://github.com/sailingsky/sqlite-test.git
Steps to reproduce
there are two records in table test:
id name
22 test22
850361281191579648 tt
run post request: https://localhost:8083/test/maps
Expected result
[{"name":"test22","id":22},{"name":" tt","id":850361281191579648}]
Actual result
[{"name":"test22","id":22},{"name":" tt","id":1881903104}]
the second record's id value is wrong. the related issue had been submit to sqlite-jdbc: https://github.com/xerial/sqlite-jdbc/issues/1177 . FYI
Comment From: harawata
Hello @sailingsky ,
You have already found the real cause, it seems.
When you are using java.util.Map
as the result type, MyBatis calls ResultSet#getColumnClassName()
to determine the Java type of the column.
And the driver determines the result based on the column value of the first row which clearly is a flawed logic and causes the problem you are experiencing.
https://github.com/xerial/sqlite-jdbc/blob/02bac1a4a5d28a08334d197d3a3bb246fab9cb05/src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java#L583-L588
I'll watch the issue https://github.com/xerial/sqlite-jdbc/issues/1177 .
Until it gets fixed, you may have to use a custom class (POJO) instead of java.util.Map
.
I am going to close this as it is a driver issue and there is nothing to fix in MyBatis side.