Search code examples
javahibernatehql

How to get Deleted Row Count in HQL


I´m making a DELETE FROM in HQL:

String queryText = DELETE FROM Books WHERE author = 'author1'

final Query query = getCurrentSession().createQuery(queryText);

query.executeUpdate();

How can I get the number of deleted rows in the query?


Solution

  • The method executeUpdate return the number of entities deleted.

    So you will get the number of deleted rows (n) by the following code :

     int n = query.executeUpdate();