Skip to content

Support for (Nested) Projections #70

Closed as not planned
Closed as not planned
@reda-alaoui

Description

@reda-alaoui

Discussed in #69

Originally posted by dohorn July 15, 2022
First of all, I think this project is a super useful and necessary addition to Spring Data JPA 👍 What I would like to accomplish right now is to use this for nested projections on lazily loaded 1-To-Many Relations.

Doing this without any entity graph usually ends in a LazyInitializationException. However annotating the projection method with an entity graph solves this issue, like so:

public interface ProductDto {
    String getName();
    List<RatingDto> getRatings();
}

public interface RatingDto {
    int getRating();
}

public interface BaseProductRepository<T extends AbstractProduct> extends Repository<T, String>, EntityGraphQuerydslPredicateExecutor<T> {
    @EntityGraph(attributePaths = {"ratings"})
    Optional<ProductDto> findById(String id);
}

As I want to do this in a dynamic way, this project would suit my purposes perfectly, if you decided to add support.

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