I use JPA to get page result from DB
Query query = entityManager.createNativeQuery("select * from Table");
int pageNumber = 6;
int pageSize = 10;
query.setFirstResult((pageNumber-1) * pageSize);
query.setMaxResults(pageSize);
List <Foo> fooList = query.getResultList();
I have question, does result in page x (ex:6) always same items each request? I tested it have same result a page each request but I'm not sure. If I use "ORDER BY" I think is same but I'm not sure if not have "ORDER BY" in native query
Without ORDER BY
clause the order of the select statement is undefined. It can be ordered by ID
or other column due to an index defined. But you have no guarantee it will remain the same with each call.
The only guarantee of having a defined order is by adding ORDER BY
clause.
This is not related to JPA
. It is just pure SQL
specification.