java JPA 和 SYS_REFCURSOR 类似 OUT 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12009418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:15:03  来源:igfitidea点击:

JPA and SYS_REFCURSOR like OUT parameter

javaplsqleclipselinksys-refcursorglassfish-4

提问by Paul Vargas

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

我想使用带有SYS_REFCURSOR类似OUT参数的JPA 调用过程。使用普通 JDBC 非常容易,但我不确定在 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;

回答by Glen Best

JPA 2.0has 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:

JPA 2.0不支持存储过程,但在JPA 2.1Java EE 7 的一部分)中添加了支持。使用 Oracle SYS_REF_CURSOR 的标准 JPA 2.1 代码示例:

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

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



回答by DataNucleus

If you want to do it with standardised JPA 2.0 then you're out of luck (apart from hacking it through the "native query" API ... it is standardised in JPA2.1.

如果您想使用标准化的 JPA 2.0 来完成它,那么您就不走运了(除了通过“本机查询”API 对其进行黑客攻击之外……它在 JPA2.1 中是标准化的。

DataNucleus JPA has supported the JPA 2.1 syntax since early 2012 (as said in the original answer, so no idea what the "current answer is out of date" is supposed to mean), shown in these docs http://www.datanucleus.org/products/accessplatform_3_3/jpa/stored_procedures.html

DataNucleus JPA 自 2012 年初开始支持 JPA 2.1 语法(如原始答案中所述,因此不知道“当前答案已过时”是什么意思),如这些文档 http://www.datanucleus 中所示。 org/products/accessplatform_3_3/jpa/stored_procedures.html