本文介绍了查询转换 - Sql到Hql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询,我需要在hql中进行转换,但我有点困惑,不知道如何编写hql中'where'子句中的条件。

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
    )

什么是hql等效的这个sql查询?

what is hql equivalent of this sql query?

推荐答案

请在下面找到HQL查询:
假设p_message& p_config是域对象名称&

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);

这篇关于查询转换 - Sql到Hql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 20:51