Skip to content
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

Add support for QueryDSL projections in JPA repositories [DATAJPA-1796] #2090

Closed
spring-projects-issues opened this issue Oct 14, 2020 · 1 comment
Assignees
Labels
in: querydsl Querydsl integration status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

marcusvoltolim opened DATAJPA-1796 and commented

QueryDSL projections

QueryDSL projections are simple DTO classes that represent a group of properties to fetch from a database. Projections may be useful when we need only a small subset of columns from the queried entities. In such cases, they help us reduce the traffic between the database and our application.

Spring Data JPA + QueryDSL

Spring Data JPA provides support for the QueryDSL library via the QuerydslPredicateExecutor interface.

 

public interface QuerydslPredicateExecutor<T> {
    Optional<T> findOne(Predicate predicate);
    Iterable<T> findAll(Predicate predicate);
    Iterable<T> findAll(Predicate predicate, Sort sort);
    Iterable<T> findAll(Predicate predicate, OrderSpecifier<?>... orders);
    Iterable<T> findAll(OrderSpecifier<?>... orders);
    Page<T> findAll(Predicate predicate, Pageable pageable);
    long count(Predicate predicate);
    boolean exists(Predicate predicate);
}

The only required step is to create a repository that extends the executor interface.

interface UserRepository extends JpaRepository<User, Long>, QuerydslPredicateExecutor<User>

From the interface definition, we can clearly see that projections are not supported - there is only one type parameter for the main entity class. Yet, we can quite easily extend the executor interface and provide support for projections and more sophisticated QueryDSL queries.

 

Article: https://www.talkischeap.dev/querydsl-projections-spring-data

 


Affects: 2.3.4 (Neumann SR4)

@gregturn
Copy link
Contributor

gregturn commented Jun 9, 2022

This request now duplicates what was resolved via #2294.

@gregturn gregturn closed this as completed Jun 9, 2022
@gregturn gregturn self-assigned this Jun 9, 2022
@gregturn gregturn added the status: duplicate A duplicate of another issue label Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: querydsl Querydsl integration status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants