0

Is is possible to limit query results using .setMaxResults(1).getResultList() and @Query - something like:

@Query("SELECT l FROM LocationLog l WHERE l.visit = :visit ORDER BY l.eventTime").setMaxResults(1).getResultList()
public LocationLog findLast(@Param("visit") Visit visit);

This code is not correct as the setMaxResults and so on is outside the @Query?l

1 Answer 1

1

You cannot set pagination options in @Query annotation, but it can be done in other way. You can change your method declaration to

public LocationLog find(@Param("visit") Visit visit, Pageable pageable);

Then you will be able to pass additional argument to query invocation:

Pageable firstFive = new PageRequest(0, 5);
LocationLog locLog = locationLogDao.find(visit, firstFive);

There's also option to know current context of the query results you can use Page interface changing method return type to Page<LocationLog>. You can find all necessary informations here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.