As an addition to ukchaudhary's answer:
So I assume its not possible to call an Oracle function using
StoredProcedureQuery?
Yes, exactly. Oracle has both stored procedures and functions.
StoredProcedureQuery
can be used to call stored procedures, but it cannot call stored functions, at least not on Oracle (hence the name).
To call a function, JPA offers the FUNCTION
keyword in JPA. This allows invoking a function from inside a JPQL query. For example, a function "hasGoodCredit" is called like this:
SELECT c FROM Customer c
WHERE FUNCTION(‘hasGoodCredit’, c.balance, c.creditLimit)
See JPA specification, Invocation of Predefined and User-defined Database Functions.
However, FUNCTION
only works inside a regular JPQL statement (SELECT, UPDATE, DELETE etc.), so it cannot be used for Oracle functions which perform data manipulation (DML), as these can only be invoked separately.
Therefore, such functions cannot be invoked via JPA. You will have to use JDBC or a native query.