【发布时间】:2020-12-07 21:36:33
【问题描述】:
我有一个包含这些字段的 Sql 表:
id uniqueidentifier primary key,
<--Omitting extra fields -->
metadata nvarchar(max)
我也有一个实体映射到它:
@Data
public class GenericEntity implements Serializable {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
@Type(type = "uuid-char")
private UUID id;
<--Omitting extra properties -->
@Type(type = "string")
private JsonNode metadata;
}
第二个字段是 JsonNode 需要能够接受不同类型的 json 并将其作为字符串存储在表中。
如何转换 JsonNode 字段并将其作为字符串存储在数据库中,然后当我从表中读取时,它会将字符串转换回 JsonNode?p>
有效载荷:
{
"id": "db8e8d4b-eee2-4507-bf30-f55c3f948724",
<-- Omitting extra properties -->
"metadata": {
"description": "Sample",
"location": "Stack Overflow"
}
}
现在每次我尝试保存它时都会收到错误:
Could not determine type for: com.fasterxml.jackson.databind.JsonNode, at table: table_name, for columns: [org.hibernate.mapping.Column(metadata)]
【问题讨论】: