Open
Description
Currently shadowed Fields are not resolved on their containing type but the declaring super type.
This causes getter/setter lookup to fail leading to mapping errors eg. in the MongoDB module.
The issue is related to Kotlin override
properties (spring-projects/spring-data-mongodb#3113) but can be experienced with Java types as well as shown in the snippet below.
interface ShadowingPropertyRepository extends MongoRepository<ShadowingProperty, String> {}
@AccessType(Type.PROPERTY)
public class ShadowedProperty {
private final String value;
public ShadowedProperty(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
@AccessType(Type.PROPERTY)
public class ShadowingProperty extends ShadowedProperty {
private @Id String id;
private String value;
@PersistenceConstructor
public ShadowingProperty(String id, String value) {
this(value);
this.id = id;
}
public ShadowingProperty(String value) {
super(value);
this.value = value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
public String getId() {
return id;
}
}
@Test
void shouldPersistShadowingProperyValue() {
ShadowingPropertyRepository repository = new MongoRepositoryFactory(template).getRepository(ShadowingPropertyRepository.class);
ShadowingProperty source = new ShadowingProperty("id-1", "val-ue");
source.setValue("The 100");
repository.save(source);
assertThat(repository.findById(source.id).get().getValue()).isEqualTo(source.getValue());
}
java.lang.IllegalArgumentException:
No getter available for persistent property private final java.lang.String ShadowedProperty.value!