createNamedStoredProcedureQuery can't find @NamedStoredProcedureQuery

This jpa call of a stored procedure is new to me and I can’t seem to call the named stored procedure query that I assigned to an entity. My Entity goes like this:

import java.util.List;  @NamedStoredProcedureQuery(         name = PolicyEntity.FUNCTION_NAME,         procedureName = PolicyEntity.PROCEDURE_NAME,         resultClasses = {PolicyEntity.class},         parameters = {                 @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class),                 @StoredProcedureParameter(mode = ParameterMode.IN, type = List.class)         }) @Entity public class PolicyEntity {     public static final String FUNCTION_NAME = "getPolicyData";     public static final String PROCEDURE_NAME = "PAP.PAYMENT_HIERARCHY.GET_POLICY_DATA";          @Column(name = "FREZ_CODE")     private String freezeCode;          @Column(name = "POL_STAT_CD")     private String polictStatus;          @Column(name = "INS_TYP_BASE")     private String insuranceType;          @Column(name = "PLAN_CODE_BASE")     private String planCode;          @Column(name = "VERS_NUM_BASE")     private String versionNumber;          @Column(name = "CRCY_CODE")     private String currency;          @Column(name = "LAST_PD_TO_DT")     private String lptd;          @Column(name = "PD_TO_DT")     private String ptd;          @Column(name = "POL_NUM")     private String policyNo;          @Column(name = "REG_TOP_UP")     private String rtu;          @Column(name = "POL_SUSP")     private String suppol;          @Column(name = "PMT_SUSP")     private String suppay;          @Column(name = "DSCNT_PREM")     private String premium;          @Column(name = "WRK_AREA")     private String workArea;          @Column(name = "CASH_LOAN_AMOUNT")     private String cashLoan;          @Column(name = "APL_AMOUNT")     private String apl; } 

The stored procedure it calls expects a list as a ParameterMode.IN kind of parameter. While I expect a result set as a return value. However, each time I try to call said NamedStoredProcedureQuery, I get the error below:

"No @NamedStoredProcedureQuery was found with that name : getPolicyData; nested exception is java.lang.IllegalArgumentException: No @NamedStoredProcedureQuery was found with that name : getPolicyData" 

The implementation that I use to call it goes like this:

@Transactional @Repository public class PolicyRepositoryImpl implements PolicyRepository {          @PersistenceContext     private EntityManager em;          @Override     public String getPolicyData(String policyNo) {         System.out.println(1);         StoredProcedureQuery query = em.createNamedStoredProcedureQuery(PolicyEntity.FUNCTION_NAME);          System.out.println(2);         List<String> policyList = new ArrayList<String>();          System.out.println(3);         policyList.add(policyNo);          System.out.println(4);         query.setParameter("POLICY_LIST", policyList);          System.out.println(5);         List<PolicyEntity> policy = query.getResultList();                  return null;     }  } 

The implementation fails when the EntityManager attempts to call the named procedure by using the createNamedStoredProcedureQuery method. It seems that it’s unable to find the named procedure that I declared. I’m in dire need to understand how to fix this.

I’m not sure if the info I provided is enough but please do ask if I need to provide more.

Add Comment
1 Answer(s)

Make sure that procedureName is the name of procedure which you created in SQL(Mysql,…). And another approach is: in repository extend Interface JpaRepository we could use @Query(value = "CALL procedureName(:param);", nativeQuery = true) void executeProcesure(@Param("param") List param);

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.