JPA and SYS_REFCURSOR like OUT parameter

Paul Vargas picture Paul Vargas · Aug 17, 2012 · Viewed 11.3k times · Source

I want to call a procedure using JPA with SYS_REFCURSOR like OUT parameter. This is very easy using plain JDBC but I'm not sure that is possible in JPA.

My procedure is like following:

CREATE OR REPLACE FUNCTION FN_GET_COINS
  RETURN SYS_REFCURSOR
IS vCursor SYS_REFCURSOR;

BEGIN
  OPEN vCursor FOR
    SELECT
      ...
  RETURN vCursor;
  CLOSE vCursor;

EXCEPTION
  ...
END FN_GET_COINS;

Answer

Glen Best picture Glen Best · Jul 17, 2013

JPA 2.0 has no support for stored procedures, but support has been added in JPA 2.1, part of Java EE 7. Examples of standard JPA 2.1 code using Oracle SYS_REF_CURSOR:

http://wiki.eclipse.org/EclipseLink/Release/2.5/JPA21#Ref_cursor_Example
http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#JPA_2.1_StoredProcedureQuery