From 4d016dbd02448941856caebc176918f8be4259c0 Mon Sep 17 00:00:00 2001 From: bthreader Date: Sat, 23 Dec 2023 18:07:24 +0000 Subject: [PATCH] #12 BikeRepository: remove @Query as not compatible with Specification --- .../java/servicecourse/repo/BikeEntitySpecification.java | 8 +++++--- .../src/main/java/servicecourse/repo/BikeRepository.java | 9 --------- 2 files changed, 5 insertions(+), 12 deletions(-) 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); }