2015-05-08 85 views
0

我試着打電話從JPA 2.1的Oracle函數和我得到這個錯誤 -從JPA 2.1調用Oracle函數?

org.hibernate.exception.GenericJDBCException: could not extract ResultSet 
... 
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 6 
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70) 
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133) 
... 

函數定義 -

FUNCTION my_function (
     username  IN VARCHAR2, 
     case_number  IN NUMBER, 
     event_type_id IN NUMBER, 
     arguments  IN VARCHAR2, 
     note   IN VARCHAR2 
    ) 
     RETURN NUMBER 
    IS 
     retval  NUMBER; 
    BEGIN 
     -- WORKING OF FUNCTION REMOVED 
     retval := 1; 

     RETURN retval; 
END; 

我打電話來此通過 -

@NamedNativeQuery(
     name="my_function",query="{ call proc_history.create_parent_event(:username, :caseNumber, :eventTypeId, :arguments, :note) }" 
) 
public class MyJPAObject { 
// 
} 

與我的DAO -

public Integer callMyFuntion() { 

    Query query = em.createNamedQuery("my_function"); 

    query.setParameter("username", "me"); 
    query.setParameter("caseNumber", 123456); 
    query.setParameter("eventTypeId", 123); 
    query.setParameter("arguments", "test"); 
    query.setParameter("note", "test"); 

    return (Integer)query.getSingleResult(); 
} 

伊夫證實我可以調用使用功能 -

DECLARE retval NUMBER; 
BEGIN retval := my_function('me', 123456, 123, 'test', 'test'); 
END; 

什麼我需要做的通過JPA來調用這個?

+0

http://stackoverflow.com/questions/3572626/calling-stored-procedure-from-java-jpa –

+0

感謝 - 這就是爲存儲過程 - 使用SP更容易,因爲它們定義了內外參數 – farrellmr

+0

{? = my_function(?,?,?,?,?)}也可以 –

回答

0

如果函數返回的數據,應該是這樣的:

query = "{ ? = call proc_history.create_parent_event(:username, :caseNumber, :eventTypeId, :arguments, :note) }"