From d58af473224b37858ef81c0346d097c119c2fb18 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 28 Feb 2019 10:21:01 +0100 Subject: [PATCH] DATAJPA-1404 - Polishing. Simplify if-empty comparison. Fix ticket references. Original pull request: #304. --- .../data/jpa/repository/query/QueryUtils.java | 5 +++-- .../repository/query/QueryUtilsIntegrationTests.java | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) 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 502a56fd1..a9da43a8d 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 @@ -614,7 +614,7 @@ public abstract class QueryUtils { * @param isPluralAttribute is the attribute of Collection type? * @param isLeafProperty is this the final property navigated by a {@link PropertyPath}? * @param isForSelection is the property navigated for the selection part of the query? - * @return wether an outer join is to be used for integrating this attribute in a query. + * @return whether an outer join is to be used for integrating this attribute in a query. */ private static boolean requiresOuterJoin(@Nullable Bindable propertyPathModel, boolean isPluralAttribute, boolean isLeafProperty, boolean isForSelection) { @@ -637,7 +637,7 @@ public abstract class QueryUtils { // outer join to avoid https://hibernate.atlassian.net/browse/HHH-12712 and // https://github.com/eclipse-ee4j/jpa-api/issues/170 boolean isInverseOptionalOneToOne = PersistentAttributeType.ONE_TO_ONE == attribute.getPersistentAttributeType() - && !getAnnotationProperty(attribute, "mappedBy", "").isEmpty(); + && StringUtils.hasText(getAnnotationProperty(attribute, "mappedBy", "")); // if this path is part of the select list we need to generate an explicit outer join in order to prevent Hibernate // to use an inner join instead. @@ -650,6 +650,7 @@ public abstract class QueryUtils { } private static T getAnnotationProperty(Attribute attribute, String propertyName, T defaultValue) { + Class associationAnnotation = ASSOCIATION_TYPES.get(attribute.getPersistentAttributeType()); if (associationAnnotation == null) { 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 7952a4f6c..1b73af226 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 @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2019 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. @@ -57,7 +57,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Integration tests for {@link QueryUtils}. - * + * * @author Oliver Gierke * @author Sébastien Péralta */ @@ -95,7 +95,7 @@ public class QueryUtilsIntegrationTests { assertThat(getNonInnerJoins(root)).hasSize(1); } - @Test // DATAJPA-1238 + @Test // DATAJPA-1404 public void createsJoinForOptionalOneToOneInReverseDirection() { doInMerchantContext(emf -> { @@ -110,7 +110,7 @@ public class QueryUtilsIntegrationTests { }); } - @Test // DATAJPA-1238 + @Test // DATAJPA-1404 public void createsNoJoinForOptionalOneToOneInNormalDirection() { doInMerchantContext(emf -> { @@ -288,7 +288,7 @@ public class QueryUtilsIntegrationTests { /** * A {@link PersistenceProviderResolver} that returns only a Hibernate {@link PersistenceProvider} and ignores others. - * + * * @author Thomas Darimont * @author Oliver Gierke */