Closed
Description
To reproduce:
Create an entity using a Kotlin data class:
data class User(
val id: String? = null,
val flags: Map<String, Any>,
)
Trying to save an instance with null id will crash:
No accessor to set property private final java.lang.String com.example.User.id!
java.lang.UnsupportedOperationException: No accessor to set property private final java.lang.String com.example.User.id!
at com.example.User_Accessor_a89b9l.setProperty(Unknown Source)
at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:104)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:63)
at org.springframework.data.mongodb.core.EntityOperations$AdaptibleMappedEntity.populateIdIfNecessary(EntityOperations.java:690)
Changing field to Map<String, String>
makes the bug disappear. Downgrading to Spring Boot 2.4.3 also removes the exception.
A minimal project reproducing the bug can be found here: https://github.com/pkubowicz/spring-data-id-accessor