JPA 2.1 @Procedure with multiple out parameters

huangapple go评论91阅读模式
英文:

JPA 2.1 @Procedure with multiple out parameters

问题

问题:调用带有多个输出参数的存储过程。

@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)
英文:

Issue: call procedure with multiple out parameters.

@Procedure(procedureName = &quot;procedureName&quot; , outputParameterName = &quot;parma1&quot;, outputParameterName = &quot;param2&quot;)
Map&lt;String, String&gt; methodName();

I am getting below error while calling method from service class.

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.&lt;init&gt;(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

得分: 0

以下是翻译好的内容:

在下方网址提供的详细信息中 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); 



/// 调用存储过程并获取结果
query.execute();
Double sum = (Double) addBookStoredProcedure.getOutputParameterValue("sum");
英文:

Detail given below web link http://roufid.com/3-ways-to-call-a-stored-procedure-with-hibernate-jpa-2-1/ work for me.

Register the procedure manually as given below.

// Dynamic stored procedure definition.

StoredProcedureQuery addBookStoredProcedure = entityManager.createStoredProcedureQuery(&quot;addBook_sp&quot;);
addBookStoredProcedure.registerStoredProcedureParameter(&quot;sum&quot;, String.class, ParameterMode.OUT); 



/// call the stored procedure and get the result
query.execute();
Double sum = (Double) addBookStoredProcedure.getOutputParameterValue(&quot;sum&quot;);

huangapple
  • 本文由 发表于 2020年10月27日 22:16:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64556387.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定