Skip to content

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

Closed
@aschmalfeld

Description

@aschmalfeld

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions