I have the same problem. For example, in a query that used the pagination functionality, the second result page contained results that were already contained in the first result page. The cause of the problem is that the two different SQL statements, which are generated by hibernate for the first page resp. all following pages, behave differently (we are using Hibernate 3.0.5 and Oracle 10.2).
For the first page, the gerated SQL looks like:
Code:
select * from (<QUERY>) where rownum <= X
For the following pages, the gerated SQL looks like this:
Code:
select * from ( select row_.*, rownum rownum_ from ( <QUERY> row_ ) where rownum_ <= X and rownum_ > Y
In some cases, the ordering of the results is not identical. In our case, all results that were returned by the actual query were equal in respect of the ordering clause of the query and this somehow caused the occurence of the same result in more than one pages. This does not happen if we also use the second kind of statement for the first page.
In my opinion, the query for the first result page should have the same syntax as for the other queries. The performance may be slower, but it is guranteed that the behavior is the same. And it would be better than to always use the workaround mentioned above (but thanx for that!). Or are there other solutions available now?
I tried to find the JIRA issue with the comments, but I did not find it. How can I find it?