diff --git a/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java b/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java index 84b7d6a67..3bb50f2ab 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java @@ -168,17 +168,22 @@ public class Jpa21Utils { } else if (parent != null && !exists(attributeName, parent.getAttributeNodes())) { parent.addAttributeNodes(attributeName); } + return; } AttributeNode node = findAttributeNode(attributeName, root, parent); + if (node != null) { Subgraph subgraph = getSubgraph(node); + if (subgraph == null) { subgraph = parent != null ? parent.addSubgraph(attributeName) : root.addSubgraph(attributeName); } + createGraph(pathComponents, offset + 1, root, subgraph); + return; } @@ -211,7 +216,7 @@ public class Jpa21Utils { * @return {@literal null} if not found. */ private static AttributeNode findAttributeNode(String attributeNodeName, EntityGraph entityGraph, - Subgraph parent) { + Subgraph parent) { return findAttributeNode(attributeNodeName, parent != null ? parent.getAttributeNodes() : entityGraph.getAttributeNodes()); } @@ -246,5 +251,4 @@ public class Jpa21Utils { private static Subgraph getSubgraph(AttributeNode node) { return node.getSubgraphs().isEmpty() ? null : node.getSubgraphs().values().iterator().next(); } - } diff --git a/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java index f83f3ba1a..33a84f3b1 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/EntityGraphRepositoryMethodsIntegrationTests.java @@ -146,9 +146,6 @@ public class EntityGraphRepositoryMethodsIntegrationTests { em.flush(); em.clear(); - em.flush(); - em.clear(); - User user = repository.getOneWithAttributeNamesById(tom.getId()); assertThat(user, is(notNullValue())); @@ -232,14 +229,16 @@ public class EntityGraphRepositoryMethodsIntegrationTests { User user = repository.findOneWithDeepGraphById(tom.getId()); assertThat(user, is(notNullValue())); - - assertThat("colleagues on root should have been fetched by dynamic subgraph declaration", + assertThat("Colleagues on root should have been fetched by dynamic subgraph declaration", Persistence.getPersistenceUtil().isLoaded(user, "colleagues"), is(true)); for (User colleague : user.getColleagues()) { + assertThat(Persistence.getPersistenceUtil().isLoaded(colleague, "colleagues"), is(true)); assertThat(Persistence.getPersistenceUtil().isLoaded(colleague, "roles"), is(true)); + for (User colleagueOfColleague : colleague.getColleagues()) { + assertThat(Persistence.getPersistenceUtil().isLoaded(colleagueOfColleague, "roles"), is(true)); assertThat(Persistence.getPersistenceUtil().isLoaded(colleagueOfColleague, "colleagues"), is(false)); } diff --git a/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java b/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java index 51e66c89a..aef97aeea 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java @@ -21,6 +21,4 @@ import org.springframework.test.context.ContextConfiguration; * @author Christoph Strobl */ @ContextConfiguration("classpath:eclipselink.xml") -public class EclipseLinkJpa21UtilsTests extends Jpa21UtilsTests { - -} +public class EclipseLinkJpa21UtilsTests extends Jpa21UtilsTests {}