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
This commit is contained in:
Christoph Strobl
2024-11-19 13:46:41 +01:00
committed by Mark Paluch
parent f8b74eda5b
commit 264ea10517
2 changed files with 10 additions and 1 deletions

View File

@@ -129,7 +129,6 @@ public class Jpa21Utils {
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);

View File

@@ -50,6 +50,7 @@ import org.springframework.util.ObjectUtils;
* @author Mark Paluch
* @author Jens Schauder
* @author Krzysztof Krason
* @author Christoph Strobl
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:application-context.xml")
@@ -166,6 +167,15 @@ class Jpa21UtilsTests {
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}.
*/