Skip to content

Dynamic projection in combination with pagination not working #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
* @author Oliver Gierke
*/
public interface CustomerRepository extends CrudRepository<Customer, Long> {
public interface CustomerRepository extends PagingAndSortingRepository<Customer, Long> {

/**
* Uses a projection interface to indicate the fields to be returned. As the projection doesn't use any dynamic
Expand Down Expand Up @@ -97,6 +98,15 @@ public interface CustomerRepository extends CrudRepository<Customer, Long> {
*/
Page<CustomerProjection> findPagedProjectedBy(Pageable pageable);

/**
* Dyanmic projections used with pagination.
*
* @param pageable
* @param projection
* @return
*/
<T> Page<T> findPagedProjectedBy(Pageable pageable, Class<T> projection);

/**
* A DTO projection using a constructor expression in a manually declared query.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ public void supportsProjectionInCombinationWithPagination() {
assertThat(page.getContent().get(0).getFirstname(), is("Carter"));
}

@Test
public void supportsDynamicProjectionInCombinationWithPagination() {

Page<CustomerProjection> page = customers
.findPagedProjectedBy(new PageRequest(0, 1, new Sort(Direction.ASC, "lastname")), CustomerProjection.class);

assertThat(page.getContent().get(0).getFirstname(), is("Carter"));
}

@Test
public void appliesProjectionToOptional() {
assertThat(customers.findOptionalProjectionByLastname("Beauford").isPresent(), is(true));
Expand Down