From 80ef3b6cf413d4cfb7308c3e8db8b3d0746aac0c Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 19 Nov 2024 13:46:00 +0100 Subject: [PATCH 1/3] Prepare issue branch. --- pom.xml | 2 +- spring-data-envers/pom.xml | 4 ++-- spring-data-jpa-distribution/pom.xml | 2 +- spring-data-jpa/pom.xml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 1847f4d2c4..86a930dada 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-jpa-parent - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT pom Spring Data JPA Parent diff --git a/spring-data-envers/pom.xml b/spring-data-envers/pom.xml index 5dcbbb69fd..6479c8fe18 100755 --- a/spring-data-envers/pom.xml +++ b/spring-data-envers/pom.xml @@ -5,12 +5,12 @@ org.springframework.data spring-data-envers - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT org.springframework.data spring-data-jpa-parent - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa-distribution/pom.xml b/spring-data-jpa-distribution/pom.xml index 38a234cb71..b2bf7b52b0 100644 --- a/spring-data-jpa-distribution/pom.xml +++ b/spring-data-jpa-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-jpa-parent - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index c6d9301c02..a54f6acefc 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-jpa - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT Spring Data JPA Spring Data module for JPA repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-jpa-parent - 3.5.0-SNAPSHOT + 3.5.x-GH-3682-SNAPSHOT ../pom.xml From 6f3251c49c9678f0193e6525170c091979f26354 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 19 Nov 2024 13:46:41 +0100 Subject: [PATCH 2/3] Lift restriction on empty JpaEntityGraph attributes. This commit removes a check preventing EntityGraphs from being created for JpaEntityGraphs without attributes. --- .../data/jpa/repository/query/Jpa21Utils.java | 1 - .../data/jpa/repository/query/Jpa21UtilsTests.java | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java index e436624215..e3133719f3 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java @@ -129,7 +129,6 @@ private static EntityGraph createDynamicEntityGraph(EntityManager em, JpaEnti Assert.notNull(em, "EntityManager must not be null"); Assert.notNull(jpaEntityGraph, "JpaEntityGraph must not be null"); Assert.notNull(entityType, "Entity type must not be null"); - Assert.isTrue(jpaEntityGraph.isAdHocEntityGraph(), "The given " + jpaEntityGraph + " is not dynamic"); EntityGraph entityGraph = em.createEntityGraph(entityType); configureFetchGraphFrom(jpaEntityGraph, entityGraph); diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsTests.java index f09d50be0e..64c015ca49 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsTests.java @@ -50,6 +50,7 @@ * @author Mark Paluch * @author Jens Schauder * @author Krzysztof Krason + * @author Christoph Strobl */ @ExtendWith(SpringExtension.class) @ContextConfiguration("classpath:application-context.xml") @@ -166,6 +167,15 @@ void errorsOnUnknownProperties() { em.createEntityGraph(User.class))); } + @Test // GH-3682 + void allowsEmptyGraph() { + + EntityGraph graph = em.createEntityGraph(User.class); + Jpa21Utils.configureFetchGraphFrom(new JpaEntityGraph("User.NoNamedEntityGraphAvailable", EntityGraphType.FETCH, new String[0]), graph); + + Assertions.assertThat(graph.getAttributeNodes()).isEmpty(); + } + /** * Lookup the {@link AttributeNode} with given {@literal nodeName} in the root of the given {@literal graph}. */ From 24334fd4be9e18bb3ecae278c6c7b40055e01f0e Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 19 Nov 2024 15:52:10 +0100 Subject: [PATCH 3/3] Deprecate JpaEntityGraph.isAdHocEntityGraph method. An EntityGraph without attributes is valid. Therefore it is not possible to determine if a given JpaEntityGraph is a dynamic one just by looking at the attributes alone. --- .../data/jpa/repository/query/JpaEntityGraph.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaEntityGraph.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaEntityGraph.java index d1a6b45935..8e403f7d0a 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaEntityGraph.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaEntityGraph.java @@ -15,7 +15,6 @@ */ package org.springframework.data.jpa.repository.query; -import java.util.Arrays; import java.util.List; import org.springframework.data.jpa.repository.EntityGraph; @@ -29,12 +28,11 @@ * * @author Thomas Darimont * @author Mark Paluch + * @author Christoph Strobl * @since 1.6 */ public class JpaEntityGraph { - private static String[] EMPTY_ATTRIBUTE_PATHS = {}; - private final String name; private final EntityGraphType type; private final List attributePaths; @@ -46,8 +44,8 @@ public class JpaEntityGraph { * @param nameFallback must not be {@literal null} or empty. */ public JpaEntityGraph(EntityGraph entityGraph, String nameFallback) { - this(StringUtils.hasText(entityGraph.value()) ? entityGraph.value() : nameFallback, entityGraph.type(), entityGraph - .attributePaths()); + this(StringUtils.hasText(entityGraph.value()) ? entityGraph.value() : nameFallback, entityGraph.type(), + entityGraph.attributePaths()); } /** @@ -65,7 +63,7 @@ public JpaEntityGraph(String name, EntityGraphType type, @Nullable String[] attr this.name = name; this.type = type; - this.attributePaths = Arrays.asList(attributePaths == null ? EMPTY_ATTRIBUTE_PATHS : attributePaths); + this.attributePaths = attributePaths != null ? List.of(attributePaths) : List.of(); } /** @@ -99,9 +97,11 @@ public List getAttributePaths() { /** * Return {@literal true} if this {@link JpaEntityGraph} needs to be generated on-the-fly. * - * @return + * @return {@literal true} if {@link #attributePaths} is not empty. * @since 1.9 + * @deprecated since 3.5 as the used evaluation does not represent wether a {@link JpaEntityGraph} is dynamic or not. */ + @Deprecated(since = "3.5", forRemoval = true) public boolean isAdHocEntityGraph() { return !attributePaths.isEmpty(); }