Hibernate JPA存储过程调用? [英] Hibernate JPA stored procedure call?
本文介绍了Hibernate JPA存储过程调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Hibernate JPA。我有以下Oracle存储过程。
CREATEORREPLACEPROCEDURE PROC_AB
(
in_name VARCHAR2,
in_lastname VARCHAR2,
out_emp_id OUTINTEGER
)
如何调用此存储过程?
解决方案
检查这个问题:
-
首先定义名为native query的存储过程:
@ javax.persistence.NamedNativeQuery(name =call_proc_ab ,query ={call PROC_AB(:cmpid,:status,?)},resultClass = Long.class,hints = {
@ javax.persistence.QueryHint(name =org.hibernate.callable然后使用以下代码执行它:
TypedQuery< Long> query = entityManager.createNamedQuery(call_proc_ab,Long.class);
query.setParameter(cmpid,cmpid);
query.setParameter(status,status);
Long empId = query.getSingleResult();
I am using Hibernate JPA. I have below Oracle Stored procedure.
CREATEORREPLACEPROCEDURE PROC_AB
(
in_name VARCHAR2,
in_lastname VARCHAR2,
out_emp_id OUTINTEGER
)
How can I invoke this stored procedure?
解决方案
Check this SO question:
First you define the stored procedure named native query:
@javax.persistence.NamedNativeQuery(name = "call_proc_ab", query = "{ call PROC_AB(:cmpid,:status,?) }", resultClass = Long.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
Then you execute it using:
TypedQuery<Long> query = entityManager.createNamedQuery("call_proc_ab", Long.class); query.setParameter("cmpid",cmpid); query.setParameter("status",status); Long empId = query.getSingleResult();
这篇关于Hibernate JPA存储过程调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文