Search code examples
javahibernatejpaspring-datajpql

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


Solution

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