Skip to content

Commit

Permalink
Lift restriction on empty JpaEntityGraph attributes.
Browse files Browse the repository at this point in the history
This commit removes a check preventing EntityGraphs from being created for JpaEntityGraphs without attributes.

Original pull request: #3684
Closes #3682
  • Loading branch information
christophstrobl authored and mp911de committed Nov 21, 2024
1 parent f8b74ed commit 264ea10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @author Mark Paluch
* @author Jens Schauder
* @author Krzysztof Krason
* @author Christoph Strobl
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:application-context.xml")
Expand Down Expand Up @@ -166,6 +167,15 @@ void errorsOnUnknownProperties() {
em.createEntityGraph(User.class)));
}

@Test // GH-3682
void allowsEmptyGraph() {

EntityGraph<User> 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}.
*/
Expand Down

0 comments on commit 264ea10

Please sign in to comment.