简体   繁体   中英

convert sql to hql

I am performing this via sql but i want to do this in hql, select statement in from ( select count(*)...) not works in hql, any sugestion and optimization would be appreciated

SELECT u.username,u.device_tocken,sr.count
from users u,
    (select count(*) as count ,ssr.recepient as res from survey_recipient ssr where      
    (ssr.is_read is false and ssr.recepient in ('abc','xyz'))group by ssr.recepient ) sr 
where 
    (u.username = sr.res and u.device_tocken is not null)

Hibernate does not support subselects in from clouse. i tried many things and gave up when i found this jira issue.

see here https://hibernate.onjira.com/browse/HHH-3356

But if you have to use subselect you can create database views and use them in your sql as normal tables.

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