Skip to content

Resolve PersistentProperty to the containing type. #2330

Open
@christophstrobl

Description

@christophstrobl

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: team-attentionAn issue we need to discuss as a team to make progressstatus: pending-design-workNeeds design work before any code can be developedtype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions