文章
问答
冒泡
PostgreSQL Used Question-Type Cast Error

Question

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: column "XXXXXX" is of type json but expression is of type character varying
  建议:You will need to rewrite or cast the expression.
  位置:159
### The error may exist in XXX.java (best guess)
### The error may involve XXX.insert-Inline
### The error occurred while setting parameters

Environment

Spring Boot

Mybatis-Plus

PostgreSQL

Descprition

The table field "XXXXXX" is JSON in PostgreSQL. 

My app config the field is a Object.

    @TableField(typeHandler = JacksonTypeHandler.class)
    private Setting setting;

When Mybatis-Plus Save Data, it will cast the object to string, but PostgreSQL not accept the string value.

Solution

Config the datasource url, add "stringtype=unspecified".

spring.datasource.url=jdbc:postgresql://xxx.xxx.xxx.xxx:5432/xxx?stringtype=unspecified


关于作者

justin
123456
获得点赞
文章被阅读