用户登录
用户注册

分享至

如何在 JPQL(Spring JPA 查询)中使用 JOIN 执行 UPDATE 语句?

  • 作者: 爱情游戏18644047
  • 来源: 51数据库
  • 2022-11-14

问题描述

这是此问题的扩展 在 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.

软件
前端设计
程序设计
Java相关