spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
737 stars 339 forks source link

PGobject is not considered a simple type. It was before. #1778

Closed blommish closed 4 weeks ago

blommish commented 2 months ago

Converters using PGobject logs warnings

@ReadingConverter
    class PGobjectToFooConverter : Converter<PGobject, Foo?> {

        override fun convert(pGobject: PGobject): Foo? {
            return pGobject.value?.let { objectMapper.readValue<Foo>(it) }
        }
    }

Warning message:

Registering converter from class to class org.postgresql.util.PGobject as writing converter although it doesn't convert to a store-supported type; You might want to check your annotation setup at the converter implementation

It seems it was added as a Simple type and then removed in this commit. Was that intended? https://github.com/spring-projects/spring-data-relational/commit/879984d2b6dee01c49c14220aa9a8460e03ad5b7#diff-39643143ab2d0d7185fb6f633054e28a2804ba993e1ae9e4e7311bdcabae7190L158

schauder commented 2 months ago

It was only removed for R2DBC since the PG* types are part of the JDBC driver and therefore not present for R2DBC.

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

blommish commented 2 months ago

@schauder https://github.com/blommish/spring-data-jdbc-test/blob/main/src/test/kotlin/no/blommish/BarRepositoryTest.kt#L42

2024-04-25T11:45:23.335+02:00 WARN 71844 --- [ Test worker] o.s.data.convert.CustomConversions : Registering converter from class org.postgresql.util.PGobject to class no.blommish.MyJson as reading converter although it doesn't convert from a store-supported type; You might want to check your annotation setup at the converter implementation 2024-04-25T11:45:23.335+02:00 WARN 71844 --- [ Test worker] o.s.data.convert.CustomConversions : Registering converter from class no.blommish.MyJson to class org.postgresql.util.PGobject as writing converter although it doesn't convert to a store-supported type; You might want to check your annotation setup at the converter implementation

schauder commented 4 weeks ago

The problem is that the simpleTypes from the dialect don't get registered with the CustomConfiguration. And this happens because you overwrite the method that does that: AbstractJdbcConfiguration.jdbcCustomConversions()

Instead overwrite userConverters(). I created a PR to that effect for your demonstrator.