与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上的azure云中运行失败:
SchemaManagementException: Schema-validation: wrong column type encountered in column [value] in table [preference] found [json (Types#OTHER)], but expecting [varchar(255)
其他主要的stackoverflow问题参考这个:postgre bug并建议设置data-source-properties: stringtype =未指明的
不幸的是,这并不能解决azure kn8 ubuntu pod中的问题。
spring.datasource.url: jdbc:postgresql://xyz:5432/dbname?stringtype=unspecified
spring.datasource.hikari.data-source-properties.stringtype: unspecified
它在局部有效的原因是spring.jpa.hibernate.ddl-auto: none(并在K8n中验证)
但是对于所有的env,这解决了这个问题:
@Enity
public class MyEntity{
@NotNull
@ToString.Exclude
//this resolved the issue
@Column(name = "value", columnDefinition = "json")
@Convert(converter = JsonSerializationConverter.class)
private Object value;
}
只是不适合zonky嵌入式postgre