Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-gh-2054-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ protected QueryHints getQueryHints() {
return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata);
}

/**
* Returns {@link QueryHints} with the query hints on the current {@link CrudMethodMetadata} for count queries.
*/
protected QueryHints getQueryHintsForCount() {
return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata).forCounts();
}

@Deprecated
@Override
public T getOne(ID id) {
Expand Down Expand Up @@ -749,7 +756,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
// Remove all Orders the Specifications might have applied
query.orderBy(Collections.emptyList());

return em.createQuery(query);
return applyRepositoryMethodMetadataForCount(em.createQuery(query));
}

/**
Expand Down Expand Up @@ -799,6 +806,21 @@ private void applyQueryHints(Query query) {
getQueryHints().withFetchGraphs(em).forEach(query::setHint);
}

private <S> TypedQuery<S> applyRepositoryMethodMetadataForCount(TypedQuery<S> query) {

if (metadata == null) {
return query;
}

applyQueryHintsForCount(query);

return query;
}

private void applyQueryHintsForCount(Query query) {
getQueryHintsForCount().forEach(query::setHint);
}

/**
* Executes a count query and transparently sums up all values returned.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.Arrays;
import java.util.Optional;
import static org.springframework.data.jpa.domain.Specification.*;

import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;

import java.util.Arrays;
import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -192,4 +193,14 @@ void doNothingWhenNonExistentInstanceGetsDeleted() {
verify(em, never()).remove(newUser);
verify(em, never()).merge(newUser);
}

@Test // GH-2054
void applyQueryHintsToCountQueriesForSpecificationPageables() {

when(query.getResultList()).thenReturn(Arrays.asList(new User(), new User()));

repo.findAll(where(null), PageRequest.of(2, 1));

verify(metadata).getQueryHintsForCount();
}
}