1 回答
TA贡献1797条经验 获得超6个赞
对于 Oracle 函数
实体类中定义的函数
@javax.persistence.NamedNativeQuery(name = "getFunc", query = "{? = call
my_function(:empName) }", resultClass = Employee.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
对于 Oracle 存储过程
创建过程与 sys_refcursor 为第一个 OUT 参数,如下所示
CREATE OR REPLACE procedure myProcedure(p_cursor out sys_refcursor,
p_val in varchar2
)
AS
BEGIN
OPEN o_cursor FOR
SELECT emp_name
FROM employees
WHERE LOWER (emp_name) LIKE lower(p_val||'%');
在实体类中定义的程序
@javax.persistence.NamedNativeQuery(name = "getProc", query = "{ call
my_procedure(?,:empName) }", resultClass = Employee.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
和最后在 DAO 类中调用函数或过程作为
Query query = entityManager.createNamedQuery("getFunc"); // if procedure then getProc
query.setParameter("empName","smith");
query.getResultList();
- 1 回答
- 0 关注
- 665 浏览
添加回答
举报