spring-projects / spring-projects/spring-data-commons
Resolve PersistentProperty to the containing type.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PersistentProperty resolution and getter/setter lookup involved in the Java ShadowingProperty example, then reproduce the shouldPersistShadowingProperyValue scenario through MongoRepositoryFactory. Done means the shadowed value property resolves to ShadowingProperty rather than ShadowedProperty, allowing the repository save and readback to succeed without the missing-getter error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100