Skip to content

@Query(name = "Pet.findByNameEqualsAlt") not considered as named query #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carlos-hernandez opened this issue Jul 30, 2021 · 0 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@carlos-hernandez
Copy link

Hi,

According to the documentation, we can use the name attribute in a @Query annotation to lookup for a named query if we provide it in the META-INF/jdbc-named-queries.properties file. However, this is not working and instead a default implementation is generated.

A simple way to reproduce this is the following, assuming we have an entity called Pet:

public interface PetRepository extends CrudRepository<Pet, Long> {
    @Query(name = "Pet.findByNameEqualsAlt")
    Pet findByNameEquals(String name);
}

Then, declare the Pet.findByNameEqualsAlt query in the META-INF/jdbc-named-queries.properties. When calling the method PetRepository#findByNameEquals the named query you declared in the properties file is not even used at all.


The bug might be related to the JdbcQueryLookupStrategy#resolveQuery method:

Here we retrieve the name for our named query using the JdbcQueryMethod#getNamedQueryName method, which is not overridden in the JdbcQueryMethod class. The implementation from QueryMethod#getNamedQueryName from Spring Data Commons is called (${domainClass}.${queryMethodName} format) and that could be the reason why our non-default named query is not used.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 30, 2021
@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 10, 2021
@schauder schauder self-assigned this Aug 10, 2021
schauder added a commit that referenced this issue Aug 31, 2021
@Query.name wasn't getting considered when trying to find a named query for a query method.

Closes #1022
mp911de pushed a commit that referenced this issue Sep 28, 2021
@Query.name wasn't considered when trying to find a named query for a query method.

Closes #1022
Original pull request: #1039.
mp911de added a commit that referenced this issue Sep 28, 2021
See #1022
Original pull request: #1039.
mp911de pushed a commit that referenced this issue Sep 28, 2021
@Query.name wasn't considered when trying to find a named query for a query method.

Closes #1022
Original pull request: #1039.
mp911de added a commit that referenced this issue Sep 28, 2021
See #1022
Original pull request: #1039.
mp911de added a commit that referenced this issue Sep 28, 2021
See #1022
Original pull request: #1039.
@mp911de mp911de added this to the 2.1.14 (2020.0.14) milestone Sep 28, 2021
@mp911de mp911de changed the title Named query with non-default name cannot be found in Spring Data JDBC repositories @Query(name = "Pet.findByNameEqualsAlt") not considered as named query Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants