From 3e95d64150626da11026cc61f83bb65dac23e959 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 +++-- .../jpa/repository/query/QueryUtilsIntegrationTests.java | 4 ++-- 2 files changed, 5 insertions(+), 4 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 d91a82cf6..1d033d9c8 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 7858d6c98..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 @@ -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 -> {