#201 - Added example for constructor expression in JPA projections.
This commit is contained in:
@@ -95,4 +95,13 @@ public interface CustomerRepository extends CrudRepository<Customer, Long> {
|
||||
* @return
|
||||
*/
|
||||
Page<CustomerProjection> findPagedProjectedBy(Pageable pageable);
|
||||
|
||||
/**
|
||||
* A DTO projection using a constructor expression in a manually declared query.
|
||||
*
|
||||
* @param firstname
|
||||
* @return
|
||||
*/
|
||||
@Query("select new example.springdata.jpa.projections.CustomerDto(c.firstname) from Customer c where c.firstname = ?1")
|
||||
Collection<CustomerDto> findDtoWithConstructorExpression(String firstname);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,15 @@ public class CustomerRepositoryIntegrationTest {
|
||||
assertThat(((TargetAware) projectedDave).getTarget(), is(instanceOf(Map.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void projectsDtoUsingConstructorExpression() {
|
||||
|
||||
Collection<CustomerDto> result = customers.findDtoWithConstructorExpression("Dave");
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result.iterator().next().getFirstname(), is("Dave"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsProjectionInCombinationWithPagination() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user