Skip to content
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

Query from method name has map entries in wrong order. #4577

Closed
aschmalfeld opened this issue Dec 1, 2023 · 3 comments
Closed

Query from method name has map entries in wrong order. #4577

aschmalfeld opened this issue Dec 1, 2023 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@aschmalfeld
Copy link

In my class which extends from MongoRepository I have a method

Optional<MyEntity> findByMyCategories(TreeMap<String, String> myCategories);

where myCategories are e.g.:

TreeMap<String, String> myCategories = new TreeMap<>(Map.of("test1", "123", "test2", "456"));

When inserted into the Mongodb the order of key value pairs is as expected from a TreeMap, but when I call the method
findByMyCategories(myCategories) the mongoDB logs suggest the wrong order was used and therefore the object was not found.

"filter":{"myCategories":{"test2":"456","test1":"123"}}

This always returns the correct results for only one key value pair, for multiple pairs it is always wrong for some pairs
and always correct for others as if it is following some pattern.

It worked correctly before the update of spring-data-mongodb from 4.1.6 to 4.2.0

A workaround is to annotate the method with @Query or @Aggregation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 1, 2023
@christophstrobl
Copy link
Member

@aschmalfeld thanks for reporting - guess that will require some digging where things go off route.

@christophstrobl christophstrobl self-assigned this Dec 1, 2023
@christophstrobl
Copy link
Member

looks like this is a side effect of #4555. The current PR #4568 will fix the ordering aspect as well.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 7, 2023
@mp911de mp911de linked a pull request Dec 11, 2023 that will close this issue
mp911de pushed a commit that referenced this issue Dec 11, 2023
mp911de pushed a commit that referenced this issue Dec 11, 2023
mp911de pushed a commit that referenced this issue Dec 11, 2023
@mp911de mp911de added this to the 4.1.7 (2023.0.7) milestone Dec 11, 2023
@mp911de
Copy link
Member

mp911de commented Dec 11, 2023

That's fixed now.

@mp911de mp911de closed this as completed Dec 11, 2023
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