简体   繁体   中英

How to avoid subquery in FROM clause to translate SQL query into hibernate query?

I have a rather simple query that works in standard SQL, but doesn't in HQL :

SELECT id 
FROM ( SELECT COUNT(*) as rows, 
              MESSAGES_ID as id 
       FROM motcles_message mm 
       WHERE motcle IN :keyWords 
       GROUP BY MESSAGES_ID) a 
WHERE a.rows = :size

Is there any way for me to avoid using a subquery in the FROM statement since HQL doesn't support it ? I know it can use subqueries in SELECT and WHERE clauses, but I can't find a solution.

SELECT MESSAGES_ID as id 
FROM motcles_message mm 
WHERE motcle IN :keyWords 
GROUP BY MESSAGES_ID
HAVING COUNT(*) = :size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM