我是他所在领域的新手,和你一样对这个问题感到好奇。不过我借此机会对其进行了测试,以下是我的观察结果,
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.
因此我想说,返回的 true 或 false 并不意味着执行成功或失败。
同样,我们必须在调用之前注册参数getOutputParameterValue
。如果我们研究一下执行情况getOutputParameterValue
,我们将能够准确找到 hibernate 提供程序(在我的例子中是 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,我们可以确认它每次测试只执行一次。 (正如我们在上面的例子中看到的)。