Laurentiu L.
Laurentiu L.

Reputation: 6686

Why does Spring data's query builder not work for limiting query results?

Context

I have defined a repository interface (JpaRepository) and i want to limit the query results (documentation). I need the first result(s) and i prefer not to use pagination for limiting query size. I would rather use the query builder mechanism built into Spring Data repository infrastructure for constraining queries over the repository entity.

Specifics

I am building queries with property traversals and static ordering along with limiting the result. It all works except limiting the result.

At first i thought the reason for the limit query failure is they might not play well together. Then i stripped it down to just limiting the result and it is not working as expected.

After stripping it to just limiting query results i have tried :

It always works with property expressions or static ordering but litimg the results is ignored.

Could it be that this does not work on all database systems ? (I use Oracle Database 11G Release 2).

Or could it be the data jpa version? I use spring-boot-starter-data-jpa which has the spring-data-jpa 1.5.2.RELEASE and spring-data-oracle with the spring-data-jdbc-core 1.0.0

I have yet to find any clues.

Upvotes: 1

Views: 941

Answers (1)

Laurentiu L.
Laurentiu L.

Reputation: 6686

It was the version.

It turns out i had an older Spring Data JPA version (1.5.2) and the Top and First keywords where only introduced after Spring Data JPA 1.7.0 .

I ended up applying pagination to my queries (usingthe the Pageable method argument).

Upvotes: 1

Related Questions