Skip to content

Commit 264ea10

Browse files
christophstroblmp911de
authored andcommitted
Lift restriction on empty JpaEntityGraph attributes.
This commit removes a check preventing EntityGraphs from being created for JpaEntityGraphs without attributes. Original pull request: #3684 Closes #3682
1 parent f8b74ed commit 264ea10

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ private static EntityGraph<?> createDynamicEntityGraph(EntityManager em, JpaEnti
129129
Assert.notNull(em, "EntityManager must not be null");
130130
Assert.notNull(jpaEntityGraph, "JpaEntityGraph must not be null");
131131
Assert.notNull(entityType, "Entity type must not be null");
132-
Assert.isTrue(jpaEntityGraph.isAdHocEntityGraph(), "The given " + jpaEntityGraph + " is not dynamic");
133132

134133
EntityGraph<?> entityGraph = em.createEntityGraph(entityType);
135134
configureFetchGraphFrom(jpaEntityGraph, entityGraph);

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* @author Mark Paluch
5151
* @author Jens Schauder
5252
* @author Krzysztof Krason
53+
* @author Christoph Strobl
5354
*/
5455
@ExtendWith(SpringExtension.class)
5556
@ContextConfiguration("classpath:application-context.xml")
@@ -166,6 +167,15 @@ void errorsOnUnknownProperties() {
166167
em.createEntityGraph(User.class)));
167168
}
168169

170+
@Test // GH-3682
171+
void allowsEmptyGraph() {
172+
173+
EntityGraph<User> graph = em.createEntityGraph(User.class);
174+
Jpa21Utils.configureFetchGraphFrom(new JpaEntityGraph("User.NoNamedEntityGraphAvailable", EntityGraphType.FETCH, new String[0]), graph);
175+
176+
Assertions.assertThat(graph.getAttributeNodes()).isEmpty();
177+
}
178+
169179
/**
170180
* Lookup the {@link AttributeNode} with given {@literal nodeName} in the root of the given {@literal graph}.
171181
*/

0 commit comments

Comments
 (0)