Spring Data JPA
  1. Spring Data JPA
  2. DATAJPA-366

Page returns false for isFirstPage even if getTotalElements() is of 0 value

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Works as Designed
    • Affects Version/s: 1.4 M1
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      I noticed that the org.springframework.data.domain.Page returns false for isFirstPage and hasPreviousPage returns true even if getTotalElements() is of 0 value.

      I reckon it should look like:

      2013-07-02 11:15:33,612 DEBUG [AdminController] ==========>>> Page number: 1
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Page size: 10
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Total elements: 0
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Total pages: 0
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Is first page: true
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Is last page: true
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Has next page: false
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Has previous page: false

      and NOT like:

      2013-07-02 11:15:33,612 DEBUG [AdminController] ==========>>> Page number: 1
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Page size: 10
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Total elements: 0
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Total pages: 0
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Is first page: false
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Is last page: true
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Has next page: false
      2013-07-02 11:15:33,613 DEBUG [AdminController] ==========>>> Has previous page: true

      Indeed the number of elements is 0 because the database table was totally empty when I ran my manual test.

      This is how I found out about the issue. Simply by accident.

        Activity

        Hide
        Oliver Gierke added a comment -

        I am not quite sure what context you refer to or who or what is creating the Page in what context. You might wanna have a look at the unit tests for PageImpl and report a unit test back that shows the erroneous behavior.

        Show
        Oliver Gierke added a comment - I am not quite sure what context you refer to or who or what is creating the Page in what context. You might wanna have a look at the unit tests for PageImpl and report a unit test back that shows the erroneous behavior.
        Hide
        Oliver Gierke added a comment -

        I am inclined to close this as works as designed. Note, that PageImpl is zero-indexed, so when you're seeing page number 1, it's the second page, hence there indeed is a previous page available.

        Show
        Oliver Gierke added a comment - I am inclined to close this as works as designed. Note, that PageImpl is zero-indexed, so when you're seeing page number 1, it's the second page, hence there indeed is a previous page available.
        Hide
        Stephane added a comment -

        Okay Oliver. Thanks for the feedback.

        Show
        Stephane added a comment - Okay Oliver. Thanks for the feedback.

          People

          • Assignee:
            Oliver Gierke
            Reporter:
            Stephane
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: