Monday, July 20, 2015

Use `IN` clause with Spring Data JPA

To use `IN` clause with Spring Data JPA,

you can do as follows:

public interface EventRepository extends JpaRepository<Event, Long> {

  Page<Event> findByLevelIn(@Param("level") Set<EventLevel> levels, Pageable pageable);

}

You can test as follows:

  @Test
  public void testFindByLevelIn() {
    Set<EventLevel> levels = new HashSet<>();
    levels.add(EventLevel.ERROR);
    levels.add(EventLevel.WARN);
    levels.add(EventLevel.INFO);

    Page<Event> events = eventRepository.findByLevelIn(levels, new PageRequest(0, 100));
    events.forEach(System.out::println);
  }

Reference:
http://stackoverflow.com/questions/18987292/spring-crudrepository-findbyinventoryidslistlong-inventoryidlist-equivalen

No comments:

Post a Comment