Skip to content

AbstractMappingContext.hasPersistentEntity(…) does not consider cached abscence [DATACMNS-1208] #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 8, 2017 · 4 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

Bartosz Kielczewski opened DATACMNS-1208 and commented

For any simple type, i.e. Date:

context.getPersistentEntity(Date::class.java) === null
context.hasPersistentEntityFor(Date::class.java) == true

Test case included.

I think it's misleading and it has implications. For example in my use case it breaks repository sorting on any subsequent invocation with Spring Data Rest and Spring Data MongoDB. That's just for starters, for once a simple type 'leaks' there, it affects other operations.

That's for PUT:

Caused by: org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.String!
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:76)
at org.springframework.data.mapping.context.PersistentEntities.lambda$getPersistentEntity$1(PersistentEntities.java:61)
at java.util.Optional.map(Optional.java:215)
at org.springframework.data.mapping.context.PersistentEntities.getPersistentEntity(PersistentEntities.java:61)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.mergeForPut(DomainObjectReader.java:141)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.lambda$mergeCollections$6(DomainObjectReader.java:460)
at java.util.Optional.map(Optional.java:215)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.mergeCollections(DomainObjectReader.java:443)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.access$200(DomainObjectReader.java:68)
at org.springframework.data.rest.webmvc.json.DomainObjectReader$MergingPropertyHandler.doWithPersistentProperty(DomainObjectReader.java:646)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:342)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.lambda$mergeForPut$0(DomainObjectReader.java:145)
at java.util.Optional.map(Optional.java:215)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.mergeForPut(DomainObjectReader.java:141)
at org.springframework.data.rest.webmvc.json.DomainObjectReader.readPut(DomainObjectReader.java:116)


Affects: 2.0.1 (Kay SR1)

Reference URL: https://pastebin.com/V0qZigKK

Issue Links:

  • DATAMONGO-1819 Discovering the preferred constructor lead to InaccessibleObjectException with Java 9

Referenced from: pull request #258, and commits d8cea8b, 875cb11

Backported to: 2.0.2 (Kay SR2)

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Related to DATAMONGO-1819 as MongoMappingContext creates PersistentEntity's for types it should not consider an entity

@spring-projects-issues
Copy link
Author

Bartosz Kielczewski commented

Fixed and added pull request

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

I went with an a lot less invasive change to let ….hasPersistentEntity(…) properly consider the cached empty Optional. Staying with optional allows us to short circuit repeated attempts to create a PersistentEntity if we already have discovered the given source type to be unsuitable

@spring-projects-issues
Copy link
Author

Bartosz Kielczewski commented

Thought I might have overstepped it here ;) I understand your reasons, thank you for fixing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants