问题
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