互换的青春
对于 Oracle 函数实体类中定义的函数@javax.persistence.NamedNativeQuery(name = "getFunc", query = "{? = callmy_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)ASBEGINOPEN o_cursor FORSELECT emp_nameFROM employeesWHERE LOWER (emp_name) LIKE lower(p_val||'%');在实体类中定义的程序@javax.persistence.NamedNativeQuery(name = "getProc", query = "{ callmy_procedure(?,:empName) }", resultClass = Employee.class, hints = {@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })和最后在 DAO 类中调用函数或过程作为Query query = entityManager.createNamedQuery("getFunc"); // if procedure then getProcquery.setParameter("empName","smith");query.getResultList();