spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.98k stars 1.41k forks source link

Spring Data JPA creates a query according to method name regardless of existing named query #3417

Closed pashazadeh closed 6 months ago

pashazadeh commented 6 months ago

I have an existing native named-query in .xml file, but my method name is according to pattern which Spring Data JPA can create a query for. So it ignores the named query regardless of the @Query(name="myQueryName") annotation, and creates the query according to method name.

By the way query is defined in hibernate .hbml.xml files and not in Spring properties file.

If I change method name (so Spring cannot create a query for), it executes my native query.

pashazadeh commented 6 months ago

My bad, seems I had a typo in .hbm.xml file,