spring-data-relational icon indicating copy to clipboard operation
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]

Open spring-projects-issues opened this issue 4 years ago • 3 comments
trafficstars

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)

spring-projects-issues avatar Dec 29 '20 08:12 spring-projects-issues

Same issue for Collections. Maybe @Column must be mandatory when using collections and map for column persistence ?

B-hamza avatar Jan 20 '21 14:01 B-hamza

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.

schauder avatar Jan 21 '21 07:01 schauder

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.

B-hamza avatar Feb 02 '21 10:02 B-hamza