I have a proyect that use to load queries this:
@Query(value = SELECT_BY_USER_ID, nativeQuery = true)
Employee findByUserId(@Param(\"userId\") String userId);
>
If you need to load SQL from resources folder, you can try spring-data-sqlfile library. It supports loading SQL queries from resources. So you just need to put your SQL queries to the resources folder and than you can reference them in SqlFromResource annotation:
@Repository
public interface UserRepository extends JpaRepository {
@SqlFromResource(path = "select_user_by_id.sql")
User findById(int userId);
}
The output will be like:
@Repository
public interface UserRepositoryGenerated extends JpaRepository {
@Query(
value = "SELECT * FROM users WHERE id = :userId",
nativeQuery = true
)
User findById(int userId);
}