I am trying to insert a row in MySQL JSON column using Java SpringBoot CrudRepository. I already skimmed through multiple posts but couldn't get answer for this.
I defined a custom query as:
@Modifying
@Transactional
@Query(value = "insert into cs_test_json(config) values (':data')", nativeQuery = true)
public void setData(@Param("data") String string);
and MySQL table(cs_test_json) is :
id int
config JSON
In my Controller I wrote
JSONObject data = new JSONObject();
data.put("name", "kc");
data.put("age", 28);
data.put("city", "Abad");
repository.setData(data.toString());
When I run this application I always get (on calling setData method) com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Invalid JSON text: "Invalid value." at position 0 in value for column 'cs_test_json.config'
Please suggest me what I am missing. I am using MySQL 8
Thank you very much.