Open Infeligo opened 2 years ago
The behaviour you describe is a bug and should get fixed. The type should NOT be considered a simple type, but custom conversions should be taken into consideration before treating it as an entity.
The type should NOT be considered a simple type
But all source types of writing converters always add to custom simple types. Moreover, all custom types in BasicRelationalConverter
are treated as simple:
if (converterRegistration.isWriting()) {
writingPairs.add(pair);
customSimpleTypes.add(pair.getSourceType()); // <<<<<<<<<<<<<<<<<<<<
if (logger.isWarnEnabled() && !converterRegistration.isSimpleTargetType()) {
logger.warn(String.format(WRITE_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType()));
}
}
Custom simple types is Set<Class<?>>
.
Why not just add this type when registering a converter for reading? The simple types set will not contain repetitions.
The code you pointed to resides in spring-data-commons
and read converters where explicitly excluded. See https://github.com/spring-projects/spring-data-mongodb/issues/1203
So we can't simply undo that change.
There are three aspects:
PGobject
should be considered a simple type as per the dialect.isEntity
too liberal without considering CustomConversions
.PGobject should be considered a simple type as per the dialect.
Related: https://github.com/spring-projects/spring-data-relational/issues/1778 but really, the problem here is with MyData
which is considered an entity and therefore causes a join to be created with a non-existing table.
We had an internal discussion and these are our findings:
isEntity
with the interpretation of mapsToASeparateTable
eventually we want to make that distinction explicit so it can take conversions properly into account.Unfortunately these changes are complex and we probably won't be able to tackle them in the near future. For the time being, please use the workaround of adding a writing converter as well.
I am using Spring Data JDBC repository to query data for report (hence, readonly). In one place I needed to convert from JSONB to a DTO. I registered a customer converter marked as
@ReadingConverter
for that purpose, but for some reason it was never called. Debugging the code, I noticed that my DTO is considered as an entity, although it should have been registered as a simple type. Debugging more I found out that only the source type of a@WritingConverter
is registered as a simple type. Adding a dummy writing converter fixed the issue for me. However, this seems unexpected and the fix adds redundant code.My code: