spring-projects / spring-projects/spring-data-mongodb
MappingException: Couldn't find PersistentEntity for type java.lang.String [DATAMONGO-2554]
Open
@christophstrobl is already working on this.
Since Dec 30, 2020.
status: pending-design-work
type: bug
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Mark Paluch opened DATAMONGO-2554 and commented
Trying to map a property name with prefix/underscore/suffix (e.g. foo_bar) where prefix matches a property results in a MappingException.
Code:
class MyType {
String foo;
}
Document target = mapper.getMappedObject(
query(where("foo_hash").is("value")).getQueryObject(),
context.getPersistentEntity(MyType.class));
org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type java.lang.String!
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:119)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.getPair(PersistentPropertyPathFactory.java:237)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.createPersistentPropertyPath(PersistentPropertyPathFactory.java:210)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.lambda$getPersistentPropertyPath$2(PersistentPropertyPathFactory.java:183)
at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.getPersistentPropertyPath(PersistentPropertyPathFactory.java:182)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.from(PersistentPropertyPathFactory.java:97)
at org.springframework.data.mapping.context.PersistentPropertyPathFactory.from(PersistentPropertyPathFactory.java:110)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:286)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.getPath(QueryMapper.java:1094)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.<init>(QueryMapper.java:968)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.<init>(QueryMapper.java:945)
at org.springframework.data.mongodb.core.convert.QueryMapper.createPropertyField(QueryMapper.java:263)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:142)
Ideally, we stop PersistentPropertyPath introspection at types that are considered simple types.
Affects: 2.1.17 (Lovelace SR17), 2.2.7 (Moore SR7), 3.0 GA (Neumann)
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.
Assessment
This issue has not been assessed yet.