如何解决具有多个out参数的JPA 2.1 @Procedure
问题:具有多个out参数的调用过程。
@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)
解决方法
以下网络链接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");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。