How can I do an UPDATE statement with JOIN in JPQL (Spring JPA Queries)?

走远了吗. 提交于 2019-12-01 11:36:31

问题


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

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);

However, i get an error as follows

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

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


回答1:


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



来源:https://stackoverflow.com/questions/44594983/how-can-i-do-an-update-statement-with-join-in-jpql-spring-jpa-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!