HopeKing
HopeKing

Reputation: 3503

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

Upvotes: 4

Views: 6421

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81862

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

Upvotes: 9

Related Questions