JDBC或Hibernate在调用存储过程时显示奇怪的行为。
以下是示例代码:
return session.createSQLQuery("select * from pr_ss_coo_10x('31748','NEWRX',null,'5053')")
..
....tolist();
投掷错误
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.loader.Loader.doList(Loader.java:2620)
at org.hibernate.loader.Loader.doList(Loader.java:2600)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
at org.hibernate.loader.Loader.list(Loader.java:2424)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1967)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
at com.mps.surescript.repository.impl.SSGetInfoRepoImpl.getBenefitCoordInformation(SSGetInfoRepoImpl.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 76 common frames omitted
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: SQL Anywhere Error -188: Not enough values for host variables
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
但是,当我通过SQL Anywhere客户端触发相同的查询时,它正常工作。 Sybase错误代码文档说
“您没有提供足够数量的主机变量 绑定变量,或语句,或SELECT列表项的数量。“
我检查过两次,结果集与Pojo正确映射。 此问题可能的根本原因是什么?
答案 0 :(得分:2)
绕过Hibernate事务管理使用PreparedStatement完成了技巧和获取结果集。
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement ps = con.prepareStatement(
"select * from pr_ss_coo_10x(@param1=?,@param2=?, @param3=?, @param4=? )");
ResultSet rs = ps.executeQuery();
这不是解决方案,只是一种解决方法。