From 79a8d89667d3fc12de4eddb9af59e3acb63dedf3 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Wed, 12 Apr 2017 11:20:16 +0200 Subject: [PATCH] DATAJPA-1087 - Apply query hints to count queries for Querydsl but leave out fetch graphs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now make sure to apply query hints also to count queries created via Querydsl Predicates but avoid applying potential fetch graphs. Please note that for the 1.x line we’ll preserve binary comparability while for 2.x we’ll change the signature of SimpleJpaRepository.getQueryHints(). Original pull request: #195. Related pull request: #196. --- .../support/QueryDslJpaRepository.java | 17 +++++++++++++++-- ...yGraphRepositoryMethodsIntegrationTests.java | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java index c1a59fb7a..3b9c79453 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2016 the original author or authors. + * Copyright 2008-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,7 @@ import com.querydsl.jpa.impl.AbstractJPAQuery; * @author Thomas Darimont * @author Mark Paluch * @author Jocelyn Ntakpe + * @author Christoph Strobl */ public class QueryDslJpaRepository extends SimpleJpaRepository implements QueryDslPredicateExecutor { @@ -200,7 +201,19 @@ public class QueryDslJpaRepository extends SimpleJpa * @return the Querydsl count {@link JPQLQuery}. */ protected JPQLQuery createCountQuery(Predicate predicate) { - return querydsl.createQuery(path).where(predicate); + AbstractJPAQuery query = querydsl.createQuery(path).where(predicate); + + CrudMethodMetadata metadata = getRepositoryMethodMetadata(); + + if (metadata == null) { + return query; + } + + for (Entry hint : metadata.getQueryHints().entrySet()) { + query.setHint(hint.getKey(), hint.getValue()); + } + + return query; } /** diff --git a/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java index e049995d0..5465ebb30 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java @@ -147,7 +147,7 @@ public class EntityGraphRepositoryMethodsIntegrationTests { } } - @Test // DATAJPA-790 + @Test // DATAJPA-790, DATACMNS-1087 public void shouldRespectConfiguredJpaEntityGraphWithPaginationAndQueryDslPredicates() { Assume.assumeTrue(currentEntityManagerIsAJpa21EntityManager(em));