1

With JPA I try to map a object of a @Entity class a postgres DB json column.

@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);
    }

When running locally it works works like a charm, but for unknown reason it fails running in azure cloud on k8n pod:

SchemaManagementException: Schema-validation: wrong column type encountered in column [value] in table [preference] found [json (Types#OTHER)], but expecting [varchar(255)

Mainly other stackoverflow issue refer this: postgre bug and suggest to set data-source-properties: stringtype=unspecified

This unfortunately does not fix the problem in azure kn8 ubuntu pod. I tried all like:

spring.datasource.url: jdbc:postgresql://xyz:5432/dbname?stringtype=unspecified
spring.datasource.hikari.data-source-properties.stringtype: unspecified
midnight
  • 112
  • 10

1 Answers1

0

the reason, why locally it worked was that spring.jpa.hibernate.ddl-auto: none (and validate in the K8n)

But for all ENVs this resolved the issue:

@Enity
public class MyEntity{

@NotNull
@ToString.Exclude
//this resolved the issue
@Column(name = "value", columnDefinition = "json")
@Convert(converter = JsonSerializationConverter.class)
private Object value;
}

just not for the zonky embedded postgre

midnight
  • 112
  • 10