Skip to content

Support projections on query methods that take a dynamic query type (Specification or Querydsl Predicate) [DATAJPA-1033] #1378

@spring-projects-issues

Description

@spring-projects-issues

Sebastian Staudt opened DATAJPA-1033 and commented

Currently there seems no (at least no obvious) way to mix projections and specifications.

class ExampleRepository extends JpaRepository<Example, Integer>, JpaSpecificationExecutor<Example> {

    // Overriden from JpaRepository, just to show the whole picture
    // Works without problems
    @Override
    List<Example> findAll();

    // A bit odd, due to the "By", but works - see DATAJPA-680
    List<ExampleProjection> findAllProjectedBy();

    // Overriden from JpaRepository, just to show the whole picture
    // Works without problems
    @Override
    List<Example> findAll(Specification<Example> spec);

    // This would be great, but doesn't work.
    List<ExampleProjection> findAllProjectedBy(Specification<Example> spec);

}

A query method like the last above causes a java.util.NoSuchElementException inside org.springframework.data.jpa.repository.query.CriteriaQueryParameterBinder#bind during query. (Which may be another problem on its own.)


Affects: 2.0 M1 (Kay), 1.11 RC1 (Ingalls), 1.10.6 (Hopper SR6)

Issue Links:

  • DATAJPA-393 Add support for QueryDSL projections in JPA repositories

Referenced from: pull request #430

107 votes, 96 watchers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions