【发布时间】:2021-08-27 13:49:28
【问题描述】:
使用 JPA,我尝试将 @Entity 类的对象映射到 postgres DB json 列。
@Enity
public class MyEntity{
@NotNull
@ToString.Exclude
@Convert(converter = JsonSerializationConverter.class)
private Object value;
}
public class JsonSerializationConverter implements AttributeConverter<Object, String> {
private static final ObjectMapper mapper = new ObjectMapper();
@SneakyThrows
@Override
public String convertToDatabaseColumn(final Object attribute) {
return mapper.writeValueAsString(attribute);
}
在本地运行时,它的工作原理就像一个魅力,但由于未知原因,它在 k8n pod 上的天蓝色云中运行失败:
SchemaManagementException: Schema-validation: wrong column type encountered in column [value] in table [preference] found [json (Types#OTHER)], but expecting [varchar(255)
主要是其他stackoverflow issue参考这个:postgre bug并建议设置 数据源属性:stringtype=unspecified
不幸的是,这并不能解决 azure kn8 ubuntu pod 中的问题。 我都试过了:
spring.datasource.url: jdbc:postgresql://xyz:5432/dbname?stringtype=unspecified
spring.datasource.hikari.data-source-properties.stringtype: unspecified
【问题讨论】:
标签: java postgresql hibernate