usertest
usertest

Reputation: 2262

Java JPQL: add an int value to the already existing one in Database

I have a table with a column that holds int values, I need to know how to write a JPQL query that, instead of overriding the existing value, it add the new value to the existing one and persist the sum. Here is the JPQL that sets a value.

UPDATE Transaction t SET t.amount = :amount WHERE t.id = :id

Upvotes: 0

Views: 731

Answers (1)

JB Nizet
JB Nizet

Reputation: 691933

Just like in SQL:

UPDATE Transaction t SET t.amount = t.amount + 1 WHERE t.id = :id

Upvotes: 3

Related Questions