Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET

一、现象

在Java中,使用mybatis-plus更新实体类对象到mysql,其中一个字段对应数据库中json数据类型,更新时报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.

image

报错信息:

Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
; Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.

二、排查

实体类,已配置字段转换器及映射关系。

image

image

上述使用lambdaUpdate()方法,直接set,list集合未被转换json字段,导致存储mysql失败

三、解决

方式1

使用updateById方法,以对象更新

image

方式2

手动转换json,存储成功

image

posted @ 2024-11-23 10:40  ccm03  阅读(211)  评论(0)    收藏  举报