为了学习使用 Oracle 存储过程的 Hibernate 4.1,我试图让一个示例尽可能简单地工作: 1. 没有传入参数 2. SYS_REFCURSOR 作为一个返回参数
我得到的是一个例外:“org.hibernate.exception.GenericJDBCException:无效的列索引”。在网上搜索几个小时来解决这个问题并没有多大帮助。
============================== 程序
CREATE OR REPLACE PROCEDURE IFC_OWNER.JPA_APPLICATION_R_TEST
( o_result_set OUT SYS_REFCURSOR )
AS
BEGIN
OPEN o_result_set FOR
SELECT APPLICATION_ID, APP_COMMON_NM, APP_DESC, APP_URL FROM APPLICATION_R;
END;
/
============================== xml调用
<sql-query name="oracleproccall" callable="true">
<return alias="application_r" class="com.myco.entities.ApplicationR"/>
<![CDATA[ call JPA_APPLICATION_R_TEST() ]]>
</sql-query>
=============================java(调用sqlQuery.getResultList()时抛出异常)
public void run() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
Query sqlQuery = entityManager.createNamedQuery("oracleproccall");
List list = sqlQuery.getResultList();
...snip...
} catch (PersistenceException ex) {
ex.printStackTrace();
} finally {
entityManager.close();
}
}
==============================实体类
@Entity
@Table(name = "APPLICATION_R", schema = "IFC_OWNER")
public class ApplicationR implements Serializable {
private int applicationId;
private String appCommonNm;
private String appDesc;
private String appUrl;
...snip...
More available if needed.
============================== 异常
## ApplicationsByStoredProc ##
Hibernate:
/* named native SQL query oracleproccall */ call JPA_APPLICATION_R_TEST()
Feb 19, 2013 2:58:07 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 17003, SQLState: 99999
Feb 19, 2013 2:58:07 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column index
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Invalid column index
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:266)
at com.myco.jpa.tests.ApplicationsByStoredProc.run(ApplicationsByStoredProc.java:37)
at com.dstoutput.jpa.JPAEntities_InFactDomain_Test.main(JPAEntities_InFactDomain_Test.java:56)
Caused by: org.hibernate.exception.GenericJDBCException: Invalid column index
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.CallableStatementProxyHandler.continueInvocation(CallableStatementProxyHandler.java:49)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy16.registerOutParameter(Unknown Source)
at org.hibernate.dialect.Oracle8iDialect.registerResultSetOutParameter(Oracle8iDialect.java:507)