1

这是我的存储过程,它有一个输出参数:

create or replace
PROCEDURE CITYMST_LIST 
(
 P_CURSOR OUT sys_refcursor
  ,CMPID IN NUMBER
, STSTATUS IN NUMBER  

) AS 
BEGIN
  OPEN P_CURSOR FOR
  SELECT * FROM city_master WHERE citycmp_id=CMPID AND city_status=STSTATUS;
END CITYMST_LIST;

在我的 hbm 配置中,我映射了存储过程:

<sql-query name="CITYMST_LIST" callable="true">
    <return  class="CityMaster">
    </return>
    { ? = call CITYMST_LIST(?,?) }

</sql-query>

I have also tried : 
    { call CITYMST_LIST(?,?) }

这是我的java代码:

    Query query = session.getNamedQuery("CITYMST_LIST");
    query.setParameter("CMPID",Cmpid);
    query.setParameter("STSTATUS",true);
    list = query.list();
4

1 回答 1

1

您可以执行以下操作以调用返回 sys_refcursor(注释)的过程

@javax.persistence.NamedNativeQuery(name = "getProc", query = "{ call
CITYMST_LIST(?,:cmpid,:status) }", resultClass = <EntityClass>.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })

在 DAOImpl 中

Query query = entityManager.createNamedQuery("getProc"); 
query.setParameter("cmpid","123"); 
query.setParameter("status","true"); 
query.getResultList(); 
于 2013-08-29T09:52:07.240 回答