spring-data-relational
spring-data-relational copied to clipboard
MapingException when persisting Entity with a property as Map<String, Object> using converter Map to (bytes[]/String) [DATAJDBC-650]
B-hamza opened DATAJDBC-650 and commented
When trying to persist an Entity like :
class Test {
private final String a;
private final Map<String, Object> b;
.... // constructor, getters
}
using Readind and Writing converters from Map to bytes[]. The write is OK. But when reading is KO with exception :
Couldn't find PersistentEntity for type class java.lang.Object!Couldn't find PersistentEntity for type class java.lang.Object!org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.Object! at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:79)
Affects: 2.1.2 (2020.0.2)
Same issue for Collections. Maybe @Column must be mandatory when using collections and map for column persistence ?
No, the problem is that Collections and similar get treated in a special way since they normally define the structure of the expected database schema. Therefore conversions so far aren't properly considered at this point.
A workaround would be to replace Map (or Collection) with a custom type which wraps the Map and can be properly converted.
Yes we use the workaround for the moment, but as an example of some use cases, it's to be possible to use the array type as in Postgres or h2, using List or a Collection. We can detect the presence of @Column to differentiate between the normally expected behavior as database schema (@MappedCollection) or as simple column, and therefore decide to convert to the specified data type.