具有多个输出参数的 JPA 2.1 @Procedure
Posted
技术标签:
【中文标题】具有多个输出参数的 JPA 2.1 @Procedure【英文标题】:JPA 2.1 @Procedure with multiple out parameters 【发布时间】:2020-10-27 14:16:24 【问题描述】:问题:调用过程带有多个输出参数。
@Procedure(procedureName = "procedureName" , outputParameterName = "parma1", outputParameterName = "param2")
Map<String, String> methodName();
从服务类调用方法时出现以下错误。
Caused by: java.lang.IllegalArgumentException: Type cannot be null
at org.hibernate.query.procedure.internal.ProcedureParameterImpl.setHibernateType(ProcedureParameterImpl.java:130)
at org.hibernate.query.procedure.internal.ProcedureParameterImpl.<init>(ProcedureParameterImpl.java:88)
at org.hibernate.procedure.internal.ProcedureCallImpl.registerParameter(ProcedureCallImpl.java:290)
at org.hibernate.procedure.internal.ProcedureCallImpl.registerStoredProcedureParameter(ProcedureCallImpl.java:579)
at org.hibernate.procedure.internal.ProcedureCallImpl.registerStoredProcedureParameter(ProcedureCallImpl.java:70)
at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.lambda$newAdhocStoredProcedureQuery$1(StoredProcedureJpaQuery.java:228)
at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
at java.base/java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:593)
at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.newAdhocStoredProcedureQuery(StoredProcedureJpaQuery.java:219)
at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.createStoredProcedure(StoredProcedureJpaQuery.java:179)
at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.doCreateQuery(StoredProcedureJpaQuery.java:103)
at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.createQuery(StoredProcedureJpaQuery.java:93)
【问题讨论】:
【参考方案1】:下面给出的详细信息链接http://roufid.com/3-ways-to-call-a-stored-procedure-with-hibernate-jpa-2-1/为我工作。
如下所示手动注册程序。
//动态存储过程定义。
StoredProcedureQuery addBookStoredProcedure = entityManager.createStoredProcedureQuery("addBook_sp");
addBookStoredProcedure.registerStoredProcedureParameter("sum", String.class, ParameterMode.OUT);
/// call the stored procedure and get the result
query.execute();
Double sum = (Double) addBookStoredProcedure.getOutputParameterValue("sum");
【讨论】:
以上是关于具有多个输出参数的 JPA 2.1 @Procedure的主要内容,如果未能解决你的问题,请参考以下文章
Spring Data JPA NamedStoredProcedureQuery 多个输出参数
具有动态查询的 JPA 也是 Hibernate 中的动态(可选)参数