Skip to content

Commit 18353c3

Browse files
Fix repo return
1 parent 46e257e commit 18353c3

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/JpaCodeBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public CodeBlock build() {
722722

723723
if (isProjecting) {
724724

725-
TypeName returnType = TypeNames.typeNameOrWrapper(methodReturn.getActualType());
725+
TypeName returnType = methodReturn.getActualTypeName();
726726
CodeBlock convertTo;
727727
if (StringUtils.hasText(context.getDynamicProjectionParameterName())) {
728728
convertTo = CodeBlock.of("$L", context.getDynamicProjectionParameterName());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.repository.aot;
17+
18+
import org.springframework.data.jpa.repository.Query;
19+
import org.springframework.data.repository.CrudRepository;
20+
import org.springframework.data.repository.NoRepositoryBean;
21+
22+
/**
23+
* @author Christoph Strobl
24+
*/
25+
@NoRepositoryBean
26+
public interface BaseRepository<T, ID> extends CrudRepository<T, ID> {
27+
28+
@Query("select u from #{#entityName} u where u.emailAddress = ?1")
29+
T findByEmailAddressViaTemplatedDeclaredInBaseRepo(String emailAddress);
30+
}

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryContributorIntegrationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ void shouldResolveTemplatedQuery() {
347347
assertThat(user.getFirstname()).isEqualTo("Han");
348348
}
349349

350+
@Test // GH-4028
351+
void shouldResolveTemplatedQueryFromBaseRepo() {
352+
353+
User user = fragment.findByEmailAddressViaTemplatedDeclaredInBaseRepo("[email protected]");
354+
355+
assertThat(user).isNotNull();
356+
assertThat(user.getFirstname()).isEqualTo("Han");
357+
}
358+
359+
350360
@Test // GH-3830
351361
void shouldEvaluateExpressionByName() {
352362

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/JpaRepositoryMetadataIntegrationTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*/
1616
package org.springframework.data.jpa.repository.aot;
1717

18-
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.*;
19-
import static org.assertj.core.api.Assertions.*;
18+
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
19+
import static org.assertj.core.api.Assertions.assertThat;
2020

2121
import java.io.IOException;
2222
import java.nio.charset.StandardCharsets;
2323

2424
import org.junit.jupiter.api.Test;
25-
2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.context.annotation.Configuration;
2827
import org.springframework.context.support.AbstractApplicationContext;
@@ -35,6 +34,7 @@
3534
* Integration tests for the {@link UserRepository} JSON metadata via {@link JpaRepositoryContributor}.
3635
*
3736
* @author Mark Paluch
37+
* @author Christoph Strobl
3838
*/
3939
@SpringJUnitConfig(classes = JpaRepositoryMetadataIntegrationTests.JpaRepositoryContributorConfiguration.class)
4040
@Transactional
@@ -74,10 +74,9 @@ void shouldDocumentDerivedQuery() throws IOException {
7474
assertThat(resource.exists()).isTrue();
7575

7676
String json = resource.getContentAsString(StandardCharsets.UTF_8);
77-
78-
assertThatJson(json).inPath("$.methods[0]").isObject().containsEntry("name", "countUsersByLastname");
79-
assertThatJson(json).inPath("$.methods[0].query").isObject().containsEntry("query",
80-
"SELECT COUNT(u) FROM org.springframework.data.jpa.domain.sample.User u WHERE u.lastname = :lastname");
77+
assertThatJson(json).inPath("$.methods[?(@.name == 'countUsersByLastname')].query").isArray().element(0).isObject()
78+
.containsEntry("query",
79+
"SELECT COUNT(u) FROM org.springframework.data.jpa.domain.sample.User u WHERE u.lastname = :lastname");
8180
}
8281

8382
@Test // GH-3830

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/aot/UserRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @author Christoph Strobl
4242
* @author Mark Paluch
4343
*/
44-
interface UserRepository extends CrudRepository<User, Integer> {
44+
interface UserRepository extends BaseRepository<User, Integer> {
4545

4646
List<User> findUserNoArgumentsBy();
4747

0 commit comments

Comments
 (0)