diff --git a/service-course-api/src/main/java/servicecourse/repo/BikeEntitySpecification.java b/service-course-api/src/main/java/servicecourse/repo/BikeEntitySpecification.java index 56825a7..2b017f3 100644 --- a/service-course-api/src/main/java/servicecourse/repo/BikeEntitySpecification.java +++ b/service-course-api/src/main/java/servicecourse/repo/BikeEntitySpecification.java @@ -20,9 +20,11 @@ public class BikeEntitySpecification { */ public static Specification from(@NonNull BikesFilterInput input) { return (root, query, cb) -> { - // Force fetch join - root.fetch("model", JoinType.INNER); - root.fetch("groupset", JoinType.INNER); + // Force fetch join on all queries apart from the count query used by JPA for paging + if (query.getResultType() != Long.class) { + root.fetch("model", JoinType.INNER); + root.fetch("groupset", JoinType.INNER); + } List predicates = new ArrayList<>(); diff --git a/service-course-api/src/main/java/servicecourse/repo/BikeRepository.java b/service-course-api/src/main/java/servicecourse/repo/BikeRepository.java index 4088b9b..de525fa 100644 --- a/service-course-api/src/main/java/servicecourse/repo/BikeRepository.java +++ b/service-course-api/src/main/java/servicecourse/repo/BikeRepository.java @@ -1,18 +1,9 @@ package servicecourse.repo; -import lombok.NonNull; -import org.jetbrains.annotations.NotNull; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface BikeRepository extends JpaRepository, JpaSpecificationExecutor { - @NonNull - @Query("SELECT b FROM BikeEntity b JOIN FETCH b.model JOIN FETCH b.groupset") - Page findAll(@NotNull Specification spec, @NotNull Pageable pageable); }