0

I have this Spring JPA repository:

@Repository
public interface MerchantUserRepository extends JpaRepository<Users, Integer> {

    Optional<Users> findByIdAndTypeIn(Integer id, String... types);
}

Is there some way to limit the returned number of rows to 1?

Peter Penzov
  • 2,352
  • 100
  • 358
  • 675

1 Answers1

0

You add a Pageable param to your query:

Optional<Users> findByIdAndTypeIn(Integer id, String... types, Pageable page);

For one result you create it like:

Pageable firstRow = PageRequest.of(0, 1);

You may consider adding a Sort object also for your query in that case

Maciej Kowalski
  • 23,799
  • 10
  • 49
  • 59