-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
About the Bug...
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of MyBatis.
-
I have confirmed this bug reproduces without 3rd party extensions (e.g. mybatis-plus).
Database Version
HSQL
JDBC Driver Version
2.7.4
Issue Description
When using fully dynamic SQL, MyBatis does not properly parse the type handler on a parameter marker. So, for example, if I write a mapper method like this:
@Insert("${sql}")
int insertUser(String sql, Map<String,Object> parameters);And then call it with code like this:
String sql = "insert into users (id, name) values (#{parameters.p1,typeHandler=test.UUIDTypeHandler}, #{parameters.p2})";
Map<String, Object> parameters = Map.of("p1", UUID.randomUUID(), "p2", "User1");
mapper.insertUser(sql, parameters);It will fail because the typeHandler on the parameter marker is not parsed correctly. This works fine in the 3.5.x versions, but fails on 3.6.0-SNAPSHOT.
(BTW, this is essentially how https://github.com/mybatis/mybatis-dynamic-sql works, so it will be a problem if this is not resolved before the 3.6.0 release)
Here's a small project that demonstrates the problem: https://github.com/jeffgbutler/mybatis-issues/tree/master/jgb-test If you change the MyBatis version to 3.5.19, the test will pass. But it fails with 3.6.0-SNAPSHOT
I believe the error lies in these lines, but I can't easily follow the logic here:
mybatis-3/src/main/java/org/apache/ibatis/builder/ParameterMappingTokenHandler.java
Lines 98 to 100 in 9a604b3
| if ((typeHandler == null || typeHandlerAlias != null) && genericType != null && genericType != Object.class) { | |
| typeHandler = resolveTypeHandler(parameterType, genericType, jdbcType, typeHandlerAlias); | |
| } |
About your report...
-
I did not use images 🖼️ for showing text information (code, error, etc.).
-
I checked the Preview and my report looks awesome! 👍