With Spring Data JpaRepository is there any capability to get select collection of given Id with some sorting. That mean I need to make enable following query. I have found some solution apply with @NamedQuery but I can't make enable it because I am using Spring-data-jap 1.4.2.RELEASE. Thanks.
public Iterable<User> findAll(Iterable<Integer> userIds) {
Sort sort = new Sort(Direction.ASC, "name");
Iterable<User> users = userRepository.findAll(userIds, sort);
return users;
}
Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.
PagingAndSortingRepository provides methods to do pagination and sort records. JpaRepository provides JPA related methods such as flushing the persistence context and delete records in a batch.
Just declare a query method like this:
public interface UserRepository extends Repository<User, Integer> {
Iterable<User> findByIdIn(Collection<Integer> ids, Sort sort);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With