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

blinkbink
  • 89
  • 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

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
JavaMan
  • 1,142
  • 12
  • 22