Skip to content

NativeQuery with Pagination validation error at startup [DATAJPA-928] #1282

Closed
@spring-projects-issues

Description

@spring-projects-issues

Miguel Martín-Forero opened DATAJPA-928 and commented

According to Example 50 at Using @Query docs, it's possible to use a native query with pagination using Pageable but in my case it's failing with a org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException.

NativeJpaQuery constructor is checking if the query has a Pageable parameter and if the queryString contains a #pageable or #sort sequence. The query has Pageable parameter but it does not contain a #pageable string:

@Query(value = "select m.* from message m left join user_prefers_category u on (u.category = m.category and u.user = ?1) join message_category c on c.id = m.category where u.categoryEnabled = 1 or m.category not in (select category from user_prefers_category us where us.user = ?1)",
            countQuery = "select count(m.*) from message m left join user_prefers_category u on (u.category = m.category and u.user = ?1) join message_category c on c.id = m.category where u.categoryEnabled = 1 or m.category not in (select category from user_prefers_category us where us.user = ?1)",
    nativeQuery = true)
    Page<Message> findByUserCategories(Integer userId, Pageable pageable);

If I provide a #pageable string at the end of the query, validation passes, but when the query executes, it fails saying that it's expecting 3 parameters instead of 2.

Funny thing is that, when the server is starting, if I set a breakpoint inside NativeJpaQuery and change containsPageableOrSortInQueryExpression from false to true manually, validation passes just fine and the query executes well, paginating


Affects: 1.10.1 (Hopper SR1), 1.10.2 (Hopper SR2)

Reference URL: http://stackoverflow.com/questions/38349930/spring-data-and-native-query-with-pagination

Issue Links:

Referenced from: pull request #246, and commits 64c668d, b7ca812, 68efc51, 8bf8e3a

Backported to: 2.0.4 (Kay SR4)

1 votes, 12 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions