-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Search by alike() criteria is broken when type alias information is not available [DATAMONGO-2620] #3474
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
Comments
Christoph Strobl commented Thanks for bringing this to our attention. Looking at the tests in PR#884 the following should work out of the box. Criteria alikeCriteria = new Criteria().alike(Example.of(savedPerson, UntypedExampleMatcher.matching()));
List<Person> foundPeople = templateSavingNoTypeInfoInDb.find(new Query(alikeCriteria), Person.class); |
Roman Puchkovskiy commented I see, the untyped matched really makes the test pass with the unmodified mapper. Thank you, I overlooked this API feature. But, on the other hand, does it even make sense to try to make a typed matching when we know that there is no type information available? Also, Anyway, please let me know about your decision about this. If you feel that the existing behavior is ok, I will close the PR |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
I wonder why I have not received any notification about this issue... |
@rpuch Sorry about that! Might be due to the recent Jira to Github issues migration. The automation added a comment to the ticket in Jira but did not (to avoid noise) try to link authors to GH users when moving tickets over. We'll be addressing this issue by updating the documentation. |
This commit adds a note explaining scenarios suitable for an UntypedExampleMatcher. Closes: #3474
Roman Puchkovskiy opened DATAMONGO-2620 and commented
It is possible to configure
MappingMongoConverter
in such a way that 'class' attribute is not saved to MongoDB. For example, the following setupwould produce the following behavior: if an entity class is annotated with
@TypeAlias
, then the corresponding type alias is saved inclass
attribute to MongoDB, otherwise no such attribute is added.This setup seems legitimate: one could decide that they do not need
class
attribute at all if they do not plan to ever use inheritance for some their entity classes.But this setup makes
Criteria.alike(Example)
queries useless: they do not find anything. This happens, becauseDefaultMongoTypeMapper#writeTypeRestrictions()
does not check whetherrestrictedMappedTypes
is empty and adds"{'class': {$in: [...]
"}} restriction even in such an (empty) case, which produces"{'class': {$in: []
"}} which matches nothing as there is simply noclass
attribute.This restriction is needed to make sure that only entities of the 'right' type are found. But if we don't have any type alias information, it seems natural to just drop the restriction
Affects: 2.2.9 (Moore SR9), 3.0.3 (Neumann SR3)
Referenced from: pull request #884
The text was updated successfully, but these errors were encountered: