如何在 JPQL(Spring JPA 查询)中使用 JOIN 执行 UPDATE 语句? [英] How can I do an UPDATE statement with JOIN in JPQL (Spring JPA Queries)?

查看:37
本文介绍了如何在 JPQL(Spring JPA 查询)中使用 JOIN 执行 UPDATE 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此问题的扩展 在 SQL 中使用 JOIN 更新语句 但我正在尝试使用 Spring Data JPQL.

This is an extension of this question Update Statement with JOIN in SQL but I am trying to use Spring Data JPQL.

我正在尝试在 JPQL 中使用 Update 和 JOIN,如下所示

I am trying to use Update along with JOIN in JPQL as follows

@Modifying
@Query("UPDATE TotalValue tv JOIN LineItems li WHERE li.totalValue.totalValueId=:totalValuedId SET tv.totalAmount =sum(li.itemTotalValue) ")
void calculateTotalAmount(@Param("totalValuedId") Long totalValuedId);

但是,我收到如下错误

org.hibernate.hql.internal.ast.QuerySyntaxException:期待set",发现JOIN"

org.hibernate.hql.internal.ast.QuerySyntaxException: expecting "set", found 'JOIN'

在 JPQL 中不能进行 UPDATE 和 JOIN 吗?有什么选择.谢谢

Is UPDATE and JOIN not possible in JPQL ? What is the alternative. Thanks

推荐答案

JPQL 语法 似乎表明 JOIN 在 UPDATE 语句中实际上是不可能的.

The JPQL syntax seems to indicate that a JOIN is actually not possible in an UPDATE statement.

这篇关于如何在 JPQL(Spring JPA 查询)中使用 JOIN 执行 UPDATE 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆