You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
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
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 theMETA-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
:Then, declare the
Pet.findByNameEqualsAlt
query in theMETA-INF/jdbc-named-queries.properties
. When calling the methodPetRepository#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 theJdbcQueryMethod
class. The implementation fromQueryMethod#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.The text was updated successfully, but these errors were encountered: