#Spring JPA - Duplicate entries

6 messages · Page 1 of 1 (latest)

robust vale
#

Hello, I have duplicates when I try to retrieve all entries of a user in a MySQL table.
I use JPA with the "pageable" object and a GROUP BY :

@Query("SELECT s FROM Service s WHERE s.userId = ?1 ORDER BY s.uploadDate DESC")
Page<Service> findAllByUserId(Integer userId, Pageable pageable);

If I ORDER BY ASC and not DESC on the upload date, there aren't duplicates, only by desc.

To be exact, the problem is that the last service of the current page appears as the first service of the next page.

pine larkBOT
#

This post has been reserved for your question.

Hey @robust vale! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

hollow tinsel
#

If there are any eager-loading relationships, then this may be an issue

#

But also you should not specify a custom jpa query for a method which takes a pageable, unless you also define an equivalent count query. And you also should not hard-code your sorting if you're using pageable

#

If you really want to force a specific sort, modify the pageable before giving it to the repository method