简体   繁体   中英

Hibernate OGM Mongodb Aggregate Query not working with JPA setFirstResult and setMaxResult while next Execution

I am using Hibernate OGM (5.2.0.Alpha1) with MongoDB (3.4)

While I am Executing

String query ="db.student.find({'collegeName' :'VNSGU'})"

for pagination With JPA setFirstResult() and setMaxResult(), It is working fine, but while executing aggregate Query

String query = "db.student.aggregate([{'$match' : {'collegeName' :'VNSGU'}}])";

List listOfStudent = entityManager.createNativeQuery(query, Student.class).setFirstResult(startPosition).setMaxResults(noOfRecords).getResultList();

Execution :

  • In database table, i have total 10 number of records where college name is 'VNSGU',

  • When startPosition = 0 and noOfRecords = 5, it will give my proper output on first execution and return 5 records,

  • And when try to execute query second time where startPosition = 5 and noOfRecords = 5, it will return empty list, because on second execution it will have total 5 no of records which is an output of first Execution (i checked it by executing query without setFirstResult() and setMaxResult() and returning total 5 records).As Per, I understood the output of earlier execution will become an input of next execution and it will return result from earlier result.

But actually what is happening and What is the solution for this..??

So indeed, it is a bug.

We opened the following issue to track the bug you reported: https://hibernate.atlassian.net/browse/OGM-1411 .

A fix is under review, it will be part of the upcoming 5.3.1.Final release.

As Per, I understood the output of earlier execution will become an input of next execution and it will return result from earlier result.

I don't think that's the issue. More likely what's happening is that Hibernate OGM cached the result of the first query and it's returning it the second time as well. This seems related to this other problem: https://hibernate.atlassian.net/browse/OGM-1375

I'll update this answer as soon as I have investigate the issue further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM