Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 621
HopeKing Avatar asked Sep 12 '25 02:09

HopeKing


1 Answers

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

like image 115
Jens Schauder Avatar answered Sep 13 '25 15:09

Jens Schauder