Skip to content

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

@carlos-hernandez

Description

@carlos-hernandez

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions