Skip to content

Couldn't find PersistentEntity for type java.lang.Object when updating a field with suffix "class" #3566

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
davebarda opened this issue Feb 21, 2021 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@davebarda
Copy link

davebarda commented Feb 21, 2021

Spring data mongodb version: 3.0.5.RELEASE

If i'm calling
mongoOperations.updateFirst(query, Map.of("field1.class", "value"), MyModel.class);
where the model has the following structure:

public class MyModel {
    private Map<String, Object> field1;
}

I receive:
Couldn't find PersistentEntity for type java.lang.Object!

After debugging, I have realized that:

<init>:76, GenericTypeAwarePropertyDescriptor (org.springframework.beans)
buildGenericTypeAwarePropertyDescriptor:361, CachedIntrospectionResults (org.springframework.beans)
<init>:295, CachedIntrospectionResults (org.springframework.beans)
forClass:178, CachedIntrospectionResults (org.springframework.beans)
getPropertyDescriptors:444, BeanUtils (org.springframework.beans)
addPersistentEntity:379, AbstractMappingContext (org.springframework.data.mapping.context)
getPersistentEntity:263, AbstractMappingContext (org.springframework.data.mapping.context)
getPersistentEntity:206, AbstractMappingContext (org.springframework.data.mapping.context)
getPersistentEntity:90, AbstractMappingContext (org.springframework.data.mapping.context)
getRequiredPersistentEntity:73, MappingContext (org.springframework.data.mapping.context)
getEntityInformation:150, MongoRepositoryFactory (org.springframework.data.mongodb.repository.support)

in CachedIntrospectionResults
we have:
java.beans.Introspector.java:205
where
beanInfo = new Introspector(beanClass=MyModel.class, null, USE_ALL_BEANINFO).getBeanInfo()
it returns

java.beans.PropertyDescriptor[name=class; values={expert=false; visualUpdate=false; hidden=false; enumerationValues=[Ljava.lang.Object;@5b1965ea; required=false}; propertyType=class java.lang.Class; readMethod=public final native java.lang.Class java.lang.Object.getClass()]

which causes issues later on, as this is not the getter intended to be used.

I believe class property descriptor should be filtered, but I wonder how it may affect other stuff.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 21, 2021
@christophstrobl christophstrobl self-assigned this Feb 22, 2021
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 2, 2021
@christophstrobl
Copy link
Member

Good catch - Thanks for reporting!

mp911de pushed a commit that referenced this issue Mar 2, 2021
This commit makes sure to skip the class property ob Object when mapping maps and their keys inside an Update.

Closes #3566
Original pull request: #3577.
mp911de pushed a commit that referenced this issue Mar 2, 2021
This commit makes sure to skip the class property ob Object when mapping maps and their keys inside an Update.

Closes #3566
Original pull request: #3577.
@mp911de mp911de closed this as completed in 52b13cc Mar 2, 2021
@mp911de mp911de added this to the 3.0.8 (Neumann SR8) milestone Mar 2, 2021
@mp911de
Copy link
Member

mp911de commented Mar 2, 2021

That's fixed now.

@davebarda
Copy link
Author

Thanks 👍

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

Successfully merging a pull request may close this issue.

4 participants