Query conversion - Sql to Hql

雨燕双飞 提交于 2019-12-13 07:24:13

问题


I have this query and I need to convert it in hql but I am little confused, don't know how to write condition presented in 'where' clause in hql.

SELECT
    message 
FROM
    p_message 
WHERE
    message_id=(
        SELECT
            a.scene 
        FROM
            p_config a 
        INNER JOIN
            p_rec_type b 
                ON a.email_id=b.email_id 
                AND rec_type=2 
        WHERE
            a.email_type=1
    )

what is hql equivalent of this sql query?


回答1:


Please find below the HQL query: Assuming that p_message & p_config are domain object names & others are attributes mapping to column.

  String hqlQuery =" SELECT message  FROM     p_message  pm WHERE pm.message_id in (SELECT a.scene FROM p_config a INNER JOIN  p_rec_type b  ON a.email_id=b.email_id AND rec_type =:rectype          WHERE a.email_type=:emailTYpe)"; 
    query = session.createQuery(hqlQuery);
    query.setParameter("rectype", 2);
    query.setParameter("emailTYpe", 1);


来源:https://stackoverflow.com/questions/12401003/query-conversion-sql-to-hql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!