在2个表上更新查询,这些表在hibernate中以多对多映射?

时间:2014-10-21 10:17:04

标签: java mysql hibernate

我尝试了不同的方式,但无法修复此查询。

我有两张桌子 MerchantOffers & MerchantStore 都映射为多对多。现在,我需要更新每个 MerchantStore 中的有效商品总数。 我试过的一些问题

"UPDATE MerchantStore ms 
SET ms.offers_count=
(
    SELECT count(mo.offer_id) 
    from MerchantOffers mo 
    JOIN 
    mo.stores ms 
    where mo.offer_status=1
)"

为此我得到了以下异常

  

引起:java.sql.SQLException:您无法在FROM子句中为更新指定目标表'MerchantStore'

当我尝试以下操作时:

"UPDATE MerchantStore ms 
JOIN ms.offers mo 
SET ms.offers_count=count(*) 
where mo.offer_status=1)"

我收到错误消息:

  

org.hibernate.hql.ast.QuerySyntaxException:期待“set”,找到'JOIN'

通过这种方式我无法编写Query.Could任何一个帮助。

先谢谢,

拉​​朱。

0 个答案:

没有答案