2015-06-17 63 views
0

我遇到了一個問題,我試圖使用Hibernate調用Oracle存儲過程,如下面的代碼片段所示。在休眠中調用存儲過程的錯誤

我的DAO類:

Query q = session.createSQLQuery(" {call PKG.PROC_GET_DATA_SET(?, :parameter1, :parameter2) }") 
      .setParameter(0, OracleTypes.CURSOR) 
      .setParameter("parameter1", "fDate") 
      .setParameter("parameter2", "tDate"); 
resultSet = q.list(); 

程序:

CREATE OR REPLACE PACKAGE BODY schema.PKG 
AS 
PROCEDURE PROC_GET_DATA_SET(
    P_CURSOR OUT SYS_REFCURSOR, 
    P_STRING1 IN  VARCHAR2, 
    P_STRING2 IN  VARCHAR2 
) 
AS 
BEGIN 
OPEN P_CURSOR FOR 
    . 
    . 
    . 

但當我致電PROC作爲DAO類中,我得到了如下錯誤。

錯誤:

PLS-00306: wrong number or types of arguments in call to 'PROC_GET_DATA_SET' 
ORA-06550: line 1, column 7: 
PL/SQL: Statement ignored 

掙扎被發現的原因。有人可以在這裏扔光嗎?

TIA,

+0

'setParameter'這是爲IN,OUT或IN OUT參數?你爲什麼不說出所有參數? – ibre5041

+0

僅適用於'OUT'參數,您應該使用'registerOutParameter'。 – ibre5041

+0

'?'是爲ref遊標,這是我的OUT參數,其餘的都是與值給出的參數。 – Prince

回答

0

您不能使用此代碼使用hibernate調用過程。見docs

The recommended call form is standard SQL92: { ? = call functionName() } or { ? = call procedureName(}. Native call syntax is not supported.

For Oracle the following rules apply:

A function must return a result set. The first parameter of a procedure must be an OUT that returns a result set. This is done by using a SYS_REFCURSOR type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR type. See Oracle literature for further information.

我建議嘗試這樣的:

{? = call PKG.PROC_GET_DATA_SET(?, ?) } 

如果這不起作用,使用session.connection()