我是他所在领域的新手,对这个问题和你一样好奇。但是我借此机会对其进行了测试,以下是我的观察结果,
According to the documentation execute() returns:
> Return true if the first result corresponds to a result set,
> and false if it is an update count or if there are no results
> other than through IN OUT and OUT parameters, if any.
所以我想说,返回的真假不代表执行成功与否。
在调用getOutputParameterValue之前,我们必须再次注册参数。如果我们查看getOutputParameterValue 的实现,我们将能够准确找到休眠提供程序(在我的情况下是 JPA)调用实际执行的位置。
进一步了解执行发生了多少次,我通过将其插入到调用过程中的另一个表来对其进行测试。
create table test_procedure_call(msg varchar2(100));
CREATE OR REPLACE PROCEDURE test (
p_in_1 IN NUMBER,
p_out_1 OUT VARCHAR2,
p_out_2 OUT VARCHAR2
) AS
BEGIN
insert into test_procedure_call values ('Executed..');
commit;
select 'FirstName'||' '||'LastName','HR' into p_out_1,p_out_2
from dual
where p_in_1=1;
END;
/
@Test
public void testStoredProcedureQuery() {
StoredProcedureQuery sp = em.createStoredProcedureQuery("test");
// set parameters
sp.registerStoredProcedureParameter("p_in_1", Integer.class, ParameterMode.IN);
sp.registerStoredProcedureParameter("p_out_1", String.class, ParameterMode.OUT);
sp.registerStoredProcedureParameter("p_out_2", String.class, ParameterMode.OUT);
sp.setParameter("p_in_1", 1);
String name = sp.getOutputParameterValue("p_out_1").toString();
String dept = sp.getOutputParameterValue("p_out_2").toString();
System.out.println("Name : " + name);
System.out.println("Department : " + dept);
}
select * from test_procedure_call;
MSG
----------------------------------------------------------------------------------------
Executed..
通过test_procedure_call这个表,我们可以确认它每次测试只执行一次。 (正如我们在上面的例子中看到的)。