package com.example.demo.Repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.example.demo.entity.WomenCareEntity;
@Repository
public interface WomenCareRepository extends JpaRepository<WomenCareEntity, Integer> {
@Query(value="select lakh_5 from women_1A_premium where :age >=min_age and :age <=max_age and year=1",nativeQuery=true)
int findPremium(int age);
"message": "JDBC exception executing SQL [select lakh_5 from women_1A_premium where ? >=min_age and ? <=max_age and year=1]; SQL [n/a]".
This is the error message. What do I need to do?
2
Answers
If you are using "Named Parameters" in the query like :age in your case, then you need to add "@Param" annotation to give a method parameter a concrete name and bind the name in the query. Modify the query like below:
spring jpa query doc: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters
It need an extra annotation in function parameter.
Correct one is as below: