Announcement Announcement Module
Collapse
No announcement yet.
MongoDB @Query with Pageable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB @Query with Pageable

    Hello,

    I'm having a really difficult time figuring out (if possible) to use the @Query annotation along with the pagable parameter.

    For instance, if I have the following in my repository

    Code:
    Page<Message> findAllByUidAndMessageId(long uid, String messageId, Pageable pageable)
    I get the resulting Page object back as expected. However, when I add the @Query annotation


    Code:
    @Query("{'uid' : ?0, 'messageId' : ?1}")
    Page<Message> findAllByUidAndMessageId(long uid, String messageId, Pageable pageable)

    I realized this is because the query is now being constructed from the @Query rather than the methodName+parameters option (so Pageable isn't part of the query anymore).

    Is there any way to use the @Query along with the Pagable parameter at the same time? If not, what are some of the possible ways to use the Pagable parameter with more advanced queries than just basic CRUD operations.

    Any help with this would be greatly appreciated.

    Thanks!

  • #2
    Actually the query created from the String based query definition should be massaged by the Pagination object handed into the method as well. Have a look at PagedExecution.execute(Query query) and why there apparently is no Pageable instance held in the execution.

    Alternatively just provide a test case showing the issue and we will have a look into it.

    Comment


    • #3
      I noticed in the test cases that the example using @Query

      Code:
      @Query("{ 'lastname' : { '$regex' : ?0, '$options' : ''}}")
      Page<Person> findByLastnameLikeWithPageable(String lastname, Pageable pageable);
      has the $options variable in the query. Is this necessary for the Pageable object to be recognized?

      Comment


      • #4
        The issue I was referring to:

        https://jira.springsource.org/browse/DATAMONGO-238

        Fixed by upgrading to latest spring-data-mongodb version.

        Comment

        Working...
        X