diff --git a/pom.xml b/pom.xml index eeaa0b9e93..6b8c9495fd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-relational-parent - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT pom Spring Data Relational Parent diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml index 03d6a5c2a0..71d4d456de 100644 --- a/spring-data-jdbc-distribution/pom.xml +++ b/spring-data-jdbc-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT ../pom.xml diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index af9ad0904e..91a2a2b3f8 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-jdbc - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethod.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethod.java index 73f8db2fb6..d5799181fa 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethod.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethod.java @@ -147,21 +147,16 @@ private String getQueryValue() { @Nullable private String getNamedQuery() { - String name = getQueryName(); + String name = getNamedQueryName(); return this.namedQueries.hasQuery(name) ? this.namedQueries.getQuery(name) : null; } - /** - * Returns the annotated query name. - * - * @return May be {@code null}. - */ - - private String getQueryName() { + @Override + public String getNamedQueryName() { String annotatedName = getMergedAnnotationAttribute("name"); - return StringUtils.hasText(annotatedName) ? annotatedName : getNamedQueryName(); + return StringUtils.hasText(annotatedName) ? annotatedName : super.getNamedQueryName(); } /** @@ -174,7 +169,6 @@ Class getRowMapperClass() { return getMergedAnnotationAttribute("rowMapperClass"); } - /** * Returns the name of the bean to be used as {@link org.springframework.jdbc.core.RowMapper} * @@ -225,24 +219,11 @@ private T getMergedAnnotationAttribute(String attribute) { /** * Returns whether the method has an annotated query. - * - * @return */ public boolean hasAnnotatedQuery() { return findAnnotatedQuery().isPresent(); } - /** - * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found - * nor the attribute was specified. - * - * @return - */ - @Nullable - String getAnnotatedQuery() { - return findAnnotatedQuery().orElse(null); - } - private Optional findAnnotatedQuery() { return lookupQueryAnnotation() // diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index 4d0a1e2f28..44def8a4db 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -330,6 +330,13 @@ public void findAllByQueryName() { assertThat(repository.findAllByNamedQuery()).hasSize(1); } + @Test // GH-1022 + public void findAllByCustomQueryName() { + + repository.save(createDummyEntity()); + assertThat(repository.findAllByCustomNamedQuery()).hasSize(1); + } + @Test // DATAJDBC-341 public void findWithMissingQuery() { @@ -567,6 +574,8 @@ private Instant createDummyBeforeAndAfterNow() { interface DummyEntityRepository extends CrudRepository { List findAllByNamedQuery(); + @Query(name = "DummyEntity.customQuery") + List findAllByCustomNamedQuery(); List findAllByPointInTimeAfter(Instant instant); diff --git a/spring-data-jdbc/src/test/resources/META-INF/jdbc-named-queries.properties b/spring-data-jdbc/src/test/resources/META-INF/jdbc-named-queries.properties index 6d47e5853d..217ad9e1a4 100644 --- a/spring-data-jdbc/src/test/resources/META-INF/jdbc-named-queries.properties +++ b/spring-data-jdbc/src/test/resources/META-INF/jdbc-named-queries.properties @@ -1 +1,2 @@ -DummyEntity.findAllByNamedQuery=SELECT * FROM DUMMY_ENTITY \ No newline at end of file +DummyEntity.findAllByNamedQuery=SELECT * FROM DUMMY_ENTITY +DummyEntity.customQuery=SELECT * FROM DUMMY_ENTITY \ No newline at end of file diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml index 4e42a006ec..7b5e54dda2 100644 --- a/spring-data-relational/pom.xml +++ b/spring-data-relational/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-relational - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT Spring Data Relational Spring Data Relational support @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.3.0-SNAPSHOT + 2.3.0-1022-named-queries-broken-SNAPSHOT