I want to create a SQL query which deletes records older than 1 hour:
@Override
public List<Cvvs> deleteOldRecordsByDate(LocalDateTime created_at) throws Exception {
String hql = "delete from " + Records.class.getName() + " e where e.created_at <= :created_at";
TypedQuery<Records> query = entityManager.createQuery(hql, Records.class).setParameter("created_at", created_at);
List<Records> records = query.getResultList();
return records;
}
But how I can get the number of the deleted records?
You use the executeUpdate on bulk updates/deletes and its return value is the number of affected rows:
int records = query.executeUpdate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With