JPA and SYS_REFCURSOR, such as the OUT parameter

I want to call a procedure using JPA with parameter SYS_REFCURSOR as OUT . It is very simple using simple JDBC, but I'm not sure if this is possible in JPA.

My procedure is similar to the 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; 
0
source share
2 answers

JPA 2.0 does not support stored procedures, but support was 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


+4
source

If you want to do this with standardized JPA 2.0, you're out of luck (besides hacking it through the "native queries" API ... it is standardized in JPA2.1.

DataNucleus JPA has supported JPA 2.1 syntax since the beginning of 2012 (as stated in the original answer, so you should not understand what the "current answer is outdated"), shown in these documents http://www.datanucleus.org/products/accessplatform_3_3/jpa /stored_procedures.html

0
source

Source: https://habr.com/ru/post/1243490/


All Articles