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

Result of dosen't match #771

fakerqu opened this issue Sep 27, 2019 · 2 comments


Copy link

fakerqu commented Sep 27, 2019

#764 Issue Basics

  • ObjectBox version (are using the latest version?): 2.3.4
  • Reproducibility: [always]

Reproducing the bug


Result of dosen't match


List<MtLogEntity> entities = ObjectBoxManager.getInstance().getMtLogEntityBox().query()
                    .filter(entity -> logFile.getName().contains(entity.getFirstLogName()))
            long count = ObjectBoxManager.getInstance().getMtLogEntityBox().query()
                    .filter(entity -> logFile.getName().contains(entity.getFirstLogName()))

Logs & stackstraces

While I was debugging the result of build().count()==1 ,but the size of entities is 0!
My database is quite simple and only contains one entity

Copy link

Thanks for reporting. query.count() does not use a given filter. So the result size will be different.

Filters only work with find() as stated in the documentation.

* Sets a filter that executes on primary query results (returned from the db core) on a Java level.
* For efficiency reasons, you should always prefer primary criteria like {@link #equal(Property, String)} if
* possible.
* A filter requires to instantiate full Java objects beforehand, which is less efficient.
* <p>
* The upside of filters is that they allow any complex operation including traversing object graphs,
* and that filtering is executed along with the query (preferably in a background thread).
* Use filtering wisely ;-).
* <p>
* Also note, that a filter may only be used along with {@link Query#find()} and
* {@link Query#forEach(QueryConsumer)} at this point.
* Other find methods will throw a exception and aggregate functions will silently ignore the filter.
public QueryBuilder<T> filter(QueryFilter<T> filter) {

So this is a documentation oversight, but we might as well throw an error as the other Query methods do.

@greenrobot-team greenrobot-team self-assigned this Sep 30, 2019
@greenrobot-team greenrobot-team added this to the 2.4.0 milestone Oct 7, 2019
Copy link

Starting with 2.4.0-RC calling count() or remove() while using a filter throws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants