diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 177f08183..f587e27f6 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -45,7 +45,6 @@ import javax.persistence.criteria.From; import javax.persistence.criteria.Join; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Path; -import javax.persistence.criteria.Root; import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.Attribute.PersistentAttributeType; import javax.persistence.metamodel.Bindable; @@ -210,11 +209,11 @@ public abstract class QueryUtils { } /** - * Adds {@literal order by} clause to the JPQL query. Uses the {@link #DEFAULT_ALIAS} to bind the sorting property to. + * Adds {@literal order by} clause to the JPQL query. Uses the first alias to bind the sorting property to. * - * @param query - * @param sort - * @return + * @param query the query string to which sorting is applied + * @param sort the sort specification to apply. + * @return the modified query string. */ public static String applySorting(String query, Sort sort) { return applySorting(query, sort, detectAlias(query)); @@ -223,10 +222,10 @@ public abstract class QueryUtils { /** * Adds {@literal order by} clause to the JPQL query. * - * @param query must not be {@literal null} or empty. - * @param sort - * @param alias - * @return + * @param query the query string to which sorting is applied. Must not be {@literal null} or empty. + * @param sort the sort specification to apply. + * @param alias the alias to be used in the order by clause. Must not be {@literal null} or empty. + * @return the modified query string. */ public static String applySorting(String query, Sort sort, String alias) { @@ -481,9 +480,9 @@ public abstract class QueryUtils { * @param sort the {@link Sort} instance to be transformed into JPA {@link javax.persistence.criteria.Order}s. * @param from must not be {@literal null}. * @param cb must not be {@literal null}. - * @return + * @return a {@link List} of {@link javax.persistence.criteria.Order}s. */ - public static List toOrders(Sort sort, From from, CriteriaBuilder cb) { + public static List toOrders(Sort sort, From from, CriteriaBuilder cb) { List orders = new ArrayList(); @@ -539,7 +538,7 @@ public abstract class QueryUtils { * @return */ @SuppressWarnings("unchecked") - private static javax.persistence.criteria.Order toJpaOrder(Order order, From from, CriteriaBuilder cb) { + private static javax.persistence.criteria.Order toJpaOrder(Order order, From from, CriteriaBuilder cb) { PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType()); Expression expression = toExpressionRecursively(from, property); @@ -584,7 +583,7 @@ public abstract class QueryUtils { * non-optional association. * * @param propertyPathModel must not be {@literal null}. - * @param for + * @param forPluralAttribute * @return */ private static boolean requiresJoin(Bindable propertyPathModel, boolean forPluralAttribute) { diff --git a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java index 0a9bfe70f..e781ba995 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsIntegrationTests.java @@ -17,6 +17,7 @@ package org.springframework.data.jpa.repository.query; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import static java.util.Collections.*; import static org.mockito.Mockito.*; import java.util.Arrays; @@ -156,7 +157,8 @@ public class QueryUtilsIntegrationTests { } @Test // DATAJPA-1080 - public void sortByJoinColumn() { + public void toOrdersCanSortByJoinColumn() { + CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(User.class); Root root = query.from(User.class); @@ -170,6 +172,7 @@ public class QueryUtilsIntegrationTests { } @Entity + @SuppressWarnings("unused") static class Merchant { @Id String id; @@ -177,6 +180,7 @@ public class QueryUtilsIntegrationTests { } @Entity + @SuppressWarnings("unused") static class Employee { @Id String id; @@ -184,6 +188,7 @@ public class QueryUtilsIntegrationTests { } @Entity + @SuppressWarnings("unused") static class Credential { @Id String id; @@ -200,7 +205,7 @@ public class QueryUtilsIntegrationTests { @Override public List getPersistenceProviders() { - return Arrays.asList(HibernateTestUtils.getPersistenceProvider()); + return singletonList(HibernateTestUtils.getPersistenceProvider()); } @Override