0

I have this problem, using native query on Hibernate. This the query :

Query query = session.createSQLQuery(
"UPDATE InvoiceItems SET current_balance = '"+current_balance+"' WHERE record_id = '"+record_id+"'");
query.executeUpdate();

but i get this error when run the query :

javax.persistence.TransactionRequiredException: Executing an update/delete query

any suggest ? i have try with this way : TransactionRequiredException Executing an update/delete query

Lazar
  • 65
  • 5

1 Answers1

1

You need a transaction.

Transaction txn = session.beginTransaction();
Query updateQuery = session.createQuery("UPDATE Post p SET p.title = ?1, p.body = ?2 WHERE p.id = ?3");
updateQuery.setParameter(1, title);
updateQuery.setParameter(2, body);
updateQuery.setParameter(3, id);
updateQuery.executeUpdate();
txn.commit();

from https://www.baeldung.com/jpa-transaction-required-exception

YCF_L
  • 51,266
  • 13
  • 85
  • 129
JavaMan
  • 994
  • 10
  • 20