调用存储过程的 Spring JPA 本机查询给出“找不到能够从类型转换的转换器" [英] Spring JPA native query to call store procedrure gives “No converter found capable of converting from type”
问题描述
我正在使用 Spring JPA,我需要一个本机查询来调用存储过程.从结果中,我只需要获得两个字段,即代码和味精.我做了一个包含两个字段代码和味精的类.它不起作用,这是我收到的错误:
I'm using Spring JPA and I need to have a native query to call stored procedure. From the result, I need to get only two fields i.e. code and msg. I made a class which contain two field code and msg. It isn't working, this is the error I'm getting:
未能完成请求:org.springframework.core.convert.ConverterNotFoundException:否发现转换器能够从类型转换[org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap]输入 [com.evampsaanga.sez.model.dto.NtnVerification]
Failed to complete request: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.evampsaanga.sez.model.dto.NtnVerification]
所以,这是我的代码:
public interface CacheOtpRepository extends JpaRepository<CacheOtp, Long> {
@Query(value = "{call verify_ntn_opt_prc(:ntnNumber, :otpCode)}", nativeQuery = true)
NtnVerification verifyNtnByOtpStoredProcedure(@Param("ntnNumber") String ntnNumber, @Param("otpCode") String otpCode);
}
}
这是我的 dto 课
public class NtnVerification {
private int code;
private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
这是我使用mysql工作台调用存储过程时的结果
Here is the result when i call stored procedure using mysql workbench
推荐答案
尝试使用spring data JPA界面投影
try using spring data JPA interface projection
public interface NtnVerification {
public int getCode;();
public String getMsg();
}
这篇关于调用存储过程的 Spring JPA 本机查询给出“找不到能够从类型转换的转换器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!