MyBatis version
3.5.3
Database vendor and version
H2
Test case or example project
https://github.com/Ikki-Dai/mybatis-reproduce.git
Steps to reproduce
- run test case
selectTest
, the customJsonTypeHandler
work fine while read and write db, - run test case
updateCorrectTest
, the customJsonTypeHandler
work fine in a static sql - run test case
updateTestError
, the customJsonTypeHandler
doesn't work while in a dynamic sql because of the<SET>
tag
Expected result
hope the custom typeHandler work fine in dynamic sql while use tags such as <SET>
or <WHERE>
Actual result
JsonTypeHandler
doesn't work
Comment From: harawata
Here is the stack trace:
org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.IllegalArgumentException: invalid comparison: com.fasterxml.jackson.databind.node.ObjectNode and java.lang.String
### The error may exist in file [/Users/ave/repo/ikki-Dai-mybatis-reproduce/target/classes/mapper/PersonMapper.xml]
### The error may involve com.example.demo.repository.PersonRepository.updatePersonError
### The error occurred while executing an update
### Cause: java.lang.IllegalArgumentException: invalid comparison: com.fasterxml.jackson.databind.node.ObjectNode and java.lang.String
at com.example.demo.repository.PersonRepositoryTest.updateTestError(PersonRepositoryTest.java:47)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.IllegalArgumentException: invalid comparison: com.fasterxml.jackson.databind.node.ObjectNode and java.lang.String
### The error may exist in file [/Users/ave/repo/ikki-Dai-mybatis-reproduce/target/classes/mapper/PersonMapper.xml]
### The error may involve com.example.demo.repository.PersonRepository.updatePersonError
### The error occurred while executing an update
### Cause: java.lang.IllegalArgumentException: invalid comparison: com.fasterxml.jackson.databind.node.ObjectNode and java.lang.String
at com.example.demo.repository.PersonRepositoryTest.updateTestError(PersonRepositoryTest.java:47)
Caused by: java.lang.IllegalArgumentException: invalid comparison: com.fasterxml.jackson.databind.node.ObjectNode and java.lang.String
at com.example.demo.repository.PersonRepositoryTest.updateTestError(PersonRepositoryTest.java:47)
The error occurs because you compare JsonNode
with String
.
<!-- NG -->
<if test=" hobby != null and hobby != '' ">
<!-- OK -->
<if test="hobby != null">
Comment From: Ikki-Dai
@harawata Thanks, so the ognl expression happens before typeHandler conversion, right?
Comment From: harawata
Type handlers set parameter to PreparedStatement. The OGNL expression is evaluated when building the statement. So, yes. :)
Comment From: Ikki-Dai
noted