0

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..??

Bharti Ladumor
  • 1,624
  • 1
  • 10
  • 17

2 Answers2

0

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.

Guillaume Smet
  • 9,921
  • 22
  • 29
  • thank you Guillaume smet.... i created PR https://github.com/bharti72ladumor/Hibernate-ogm-mongodb-testing/blob/master/src/main/java/com/bharti/controller/MyController.java. now you can open it. – Bharti Ladumor Feb 27 '18 at 18:44
0

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.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
  • Thanks davide..but in the case of other query execution like db.student.find({'collegeName' :'VNSGU'}) , pagination is working fine..Does hibernate OGM is not maintaining cache for them..??? – Bharti Ladumor Feb 27 '18 at 14:15
  • The code is a bit different in the two scenarios. It's possible that something is affecting one case but not the other. I'll let you know as soon as I figure out what's going on – Davide D'Alto Feb 27 '18 at 14:45