diff --git a/pom.xml b/pom.xml index 49f36d7e04..42dd5c7ee4 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-jpa-parent - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT pom Spring Data JPA Parent diff --git a/spring-data-envers/pom.xml b/spring-data-envers/pom.xml index c54fa73c20..b84daadc58 100755 --- a/spring-data-envers/pom.xml +++ b/spring-data-envers/pom.xml @@ -5,12 +5,12 @@ org.springframework.data spring-data-envers - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT org.springframework.data spring-data-jpa-parent - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa-distribution/pom.xml b/spring-data-jpa-distribution/pom.xml index 954a3a249b..3db63a9ce5 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 - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index d26ca6b94b..ad09bc7142 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -7,7 +7,7 @@ org.springframework.data spring-data-jpa - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT Spring Data JPA Spring Data module for JPA repositories. @@ -16,7 +16,7 @@ org.springframework.data spring-data-jpa-parent - 4.1.0-SNAPSHOT + 4.1.x-GH-4097-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaCodeBlocks.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaCodeBlocks.java index 68b24d7d73..173a4f9074 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaCodeBlocks.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaCodeBlocks.java @@ -559,23 +559,22 @@ private CodeBlock applyEntityGraph(AotEntityGraph entityGraph, String queryVaria CodeBlock.Builder builder = CodeBlock.builder(); + String entityGraphVariable = context.localVariable("entityGraph"); if (StringUtils.hasText(entityGraph.name())) { builder.addStatement("$T $L = $L.getEntityGraph($S)", jakarta.persistence.EntityGraph.class, - context.localVariable("entityGraph"), - context.fieldNameOf(EntityManager.class), entityGraph.name()); + entityGraphVariable, context.fieldNameOf(EntityManager.class), entityGraph.name()); } else { - builder.addStatement("$T<$T> $L = $L.createEntityGraph($T.class)", - jakarta.persistence.EntityGraph.class, context.getDomainType(), - context.localVariable("entityGraph"), - context.fieldNameOf(EntityManager.class), context.getDomainType()); + builder.addStatement("$T<$T> $L = $L.createEntityGraph($T.class)", jakarta.persistence.EntityGraph.class, + context.getDomainType(), entityGraphVariable, context.fieldNameOf(EntityManager.class), + context.getDomainType()); for (String attributePath : entityGraph.attributePaths()) { String[] pathComponents = StringUtils.delimitedListToStringArray(attributePath, "."); - StringBuilder chain = new StringBuilder(context.localVariable("entityGraph")); + StringBuilder chain = new StringBuilder(entityGraphVariable); for (int i = 0; i < pathComponents.length; i++) { if (i < pathComponents.length - 1) { @@ -587,11 +586,10 @@ private CodeBlock applyEntityGraph(AotEntityGraph entityGraph, String queryVaria builder.addStatement(chain.toString(), (Object[]) pathComponents); } - - builder.addStatement("$L.setHint($S, $L)", queryVariableName, entityGraph.type().getKey(), - context.localVariable("entityGraph")); } + builder.addStatement("$L.setHint($S, $L)", queryVariableName, entityGraph.type().getKey(), entityGraphVariable); + return builder.build(); } diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryContributorIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryContributorIntegrationTests.java index eb0c09a982..67b8b06f01 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryContributorIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryContributorIntegrationTests.java @@ -637,13 +637,12 @@ void shouldApplyQueryHints() { .withMessageContaining("No enum constant jakarta.persistence.CacheStoreMode.foo"); } - @Test // GH-3830 + @Test // GH-3830, GH-4097 void shouldApplyNamedEntityGraph() { User chewie = fragment.findWithNamedEntityGraphByFirstname("Chewbacca"); - assertThat(chewie.getManager()).isInstanceOf(HibernateProxy.class); - assertThat(chewie.getRoles()).isNotInstanceOf(HibernateProxy.class); + assertThat(chewie.getManager()).isNotInstanceOf(HibernateProxy.class); } @Test // GH-3830 diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/UserRepository.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/UserRepository.java index 2285217d7e..aa4b55fa77 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/UserRepository.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/UserRepository.java @@ -246,7 +246,7 @@ List findWithParameterNameByLastnameStartingWithOrLastnameEndingWith(@Para @QueryHints(value = { @QueryHint(name = "jakarta.persistence.cache.storeMode", value = "foo") }, forCounting = false) List findHintedByLastname(String lastname); - @EntityGraph(type = EntityGraph.EntityGraphType.FETCH, value = "User.overview") + @EntityGraph(type = EntityGraph.EntityGraphType.FETCH, value = "User.detail") User findWithNamedEntityGraphByFirstname(String firstname); @EntityGraph(type = EntityGraph.EntityGraphType.FETCH, attributePaths = { "roles", "manager.roles" })