Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.x-GH-4097-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ List<User> findWithParameterNameByLastnameStartingWithOrLastnameEndingWith(@Para
@QueryHints(value = { @QueryHint(name = "jakarta.persistence.cache.storeMode", value = "foo") }, forCounting = false)
List<User> 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" })
Expand Down
Loading