使用join时更新查询的hibernate HQL错误

时间:2013-02-19 10:21:37

标签: hibernate hql

在hibernate中执行此查询时获取“org.hibernate.hql.ast.QuerySyntaxException:意外令牌:ON第1行,第132列附近”的错误。任何人都可以帮我解决我的代码如何使用ON进行休眠。

Session session  = (Session) em1.getDelegate();

org.hibernate.Query q=session.createQuery("UPDATE sc_ob_temp_audit set export_flag ='Y' WHERE audit_id IN(select a.audit_id FROM sc_ob_temp_audit a JOIN sc_ob_allocation b  ON a.sc_ob_profile_code = b.sc_ob_profile_code AND a.sc_orig_country= b.sc_orig_country LEFT OUTER JOIN sc_fac_group f ON   b.sc_orig_country = f.sc_orig_country AND b.sc_orig_sf_group_code = f.sc_fac_group_code LEFT OUTER JOIN (SELECT e.gp_cnt_cd,d.sc_prod_cont_code,d.sc_prod_group_code,d.sc_orig_country, e.gp_cd FROM sc_ob_prod_group d LEFT OUTER JOIN gbl_product e ON d.sc_prod_cont_code = e. gp_cnt_cd)de ON b.sc_orig_country = de.sc_orig_country AND b.sc_prod_cont_group_code=de.sc_prod_group_code WHERE a.sc_orig_country=:countryCd AND a.export_flag= 'N')");

q.setParameter("countryCd", country.trim());

q.executeUpdate();

3 个答案:

答案 0 :(得分:1)

您正在尝试执行SQL查询 - 为此,您必须使用SQLQuery对象。要获得SQLQuery个对象,只需致电session.createSqlQuery

另一方面 - 如果你最终编写SQL语句,为什么要使用Hibernate?您是否已映射sc_ob_temp_audit表?

答案 1 :(得分:0)

查看您的查询后,它似乎不是一个hql。它看起来像一个SQL查询。 使用session.createSqlSquery而不是session.createQuery。

答案 2 :(得分:0)

您需要先了解有关HQL语法的更多信息..

另见:

相关问题