java.lang.illegalargumentexception 没有为该名称定义查询 [...]

java.lang.illegalargumentexception no query defined for that name [...]

我在 plsql 中有一个像这样的本机查询;

create or replace package body DBPK_Monitoring is
  PROCEDURE monitoring_Search(cur OUT SYS_REFCURSOR,) is
    query       VARCHAR(30000);
    whereClause VARCHAR(10000);

  BEGIN
    whereClause := whereClause || '  and   ( cnt.contract_status!=7)';

    query := ' select itemTitle as "itemTitle", numberOfRow as "numberOfRow" ,
               orderNumber as "orderNumber",createDate as "createDate",
               priorityNumber as  "priorityNumber"  
        from buy_buy_order bbo
       inner join buy_buy_order_item bbi
          on bbi.buy_order_id = bbo.id
        left outer join core_User_Role shoUserRole
          on shoUserRole.id = bbi.buy_Expert_Id      

         ' || whereClause || ' order by ' || orderBy ||
             ') e  WHERE e.rowNO>  ' || lower_Bound || ' and e.rowNO<=' ||
             upper_Bound;
    OPEN cur FOR query
  end monitoring_Search;

end DBPK_Monitoring;

我在带有 hql 的存储库中使用此查询,如下所示:

 Session session = getSession();
        Query query = session.getNamedQuery("monitoring_Search").setResultTransformer(Transformers.aliasToBean(MonitoringDto.class));
        int firstResultIndex = searchOption.getPageNumber() * searchOption.getPageSize();
        query.setInteger("lower_Bound", firstResultIndex);
        query.setParameter("upper_Bound", firstResultIndex + searchOption.getPageSize());
        query.setString("orderBy", searchOption.getOrder());
        query.setParameter("buyOrderNumber", buyOrderNumber);        
        List<MonitoringDto> list = query.list();
        int count = (list.size() > 0L) ? list.get(0).getNumberOfRow() : 0;
        return new QueryResult<MonitoringDto>(searchOption.getPageNumber(), count, searchOption.getPageSize(), list);

当我运行编程时,我得到这个错误:

java.lang.illegalargumentexception no query defined for that name [monitoring_Search]

我该如何解决这个问题?

您必须将 monitoring_search 定义为 Hibernate 命名查询,您可以在 link 中查看有关此的详细信息:https://www.baeldung.com/hibernate-named-query 祝你有美好的一天并亲吻你周围的人 ;)