Can HQL Select on the result set of another query?

前端 未结 4 981
情话喂你
情话喂你 2020-12-10 11:15

Can HQL Select on the result set of another query?
For example:

SELECT COUNT(*) FROM (SELECT * FROM Table)


I can do it in SQL but w

4条回答
  •  粉色の甜心
    2020-12-10 11:53

    there is no way to do subquery in from clause in HQL even if the database support it, I solved this problem by putting the query into the sql as a store procedure, then call the procedure in HQL. For example:

    Insert the procedure into your sql:

    DELIMITER $$
    CREATE PROCEDURE `procedure_name`(
      `arg_name` INT,
    ) BEGIN
         your query here
    END;
    $$
    DELIMITER ;
    

    Then, if you use hibernate, call this procedure from java code as below:

    Query query = session.createSQLQuery("CALL procedure_name(:arg_name)");
    query.setParameter("arg_name", args);
    List list = query.list();
    

    Hope this can help you.

提交回复
热议问题