Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调用从Hibernate返回记录列表的PL/SQL函数_Java_Hibernate_Plsql - Fatal编程技术网

Java 调用从Hibernate返回记录列表的PL/SQL函数

Java 调用从Hibernate返回记录列表的PL/SQL函数,java,hibernate,plsql,Java,Hibernate,Plsql,在尝试调用这样的PL/SQL函数时 type t_messages_rec is record ( id NUMBER ,code VARCHAR2(30) ,type VARCHAR2(3) ,text VARCHAR2(100) ); type t_messages_tab is table of t_messages_rec; function get_and_clear_messages return t_messages_tab pipelined; 来

在尝试调用这样的PL/SQL函数时

type t_messages_rec is record (
   id NUMBER
  ,code VARCHAR2(30)
  ,type VARCHAR2(3)
  ,text VARCHAR2(100)
);
  
type t_messages_tab is table of t_messages_rec;
  
function get_and_clear_messages return t_messages_tab
pipelined;
来自java

import javax.persistence.EntityManager;
import oracle.jdbc.OracleTypes;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.jdbc.ReturningWork;

// imports are listed for clarity 
    
    ReturningWork work = connection -> {
      try (CallableStatement function = connection.prepareCall("{ ? = call PACKAGE_NAME.get_and_clear_messages() }")) {
        function.registerOutParameter(1, OracleTypes.REF_CURSOR);
        function.execute();

        return function.getResultSet();
      }
    };

    Session session = entityManager.unwrap(Session.class);
    try {
      return (List<Message>) session.doReturningWork(work);
    } catch (HibernateException e) {
      e.printStackTrace();
    }
我怀疑(但我可能错了),这条线

意味着我要将调用的结果存储在“?”变量中,这是流水线函数所不允许的


使用Hibernate从管道函数中获取结果的正确方法是什么?

我把它整理好了。显然,可以使用标准sql查询流水线函数:)

例:

Caused by: Error : 6550, Sql = BEGIN :1 := PACKAGE_NAME.get_and_clear_messages() ; END;,
OriginalSql = { ? = call PACKAGE_NAME.get_and_clear_messages() }, 
Error Msg = ORA-06550: line 61, column 12:
PLS-00653: aggregate/table functions are not allowed
  try (CallableStatement function = connection.prepareCall("{ ? = call PACKAGE_NAME.get_and_clear_messages() }")) {
SELECT * FROM PACKAGE_NAME.GET_AND_CLEAR_MESSAGES() m