String hql = "update Employee set salary = :newSalary where id = :employeeId"; Query query = session.createQuery(hql); query.setParameter("newSalary", 50000); query.setParameter("employeeId", 100); int result = query.executeUpdate();
String hql = "delete from Employee where hireDate > :cutoffDate"; Query query = session.createQuery(hql); query.setParameter("cutoffDate", LocalDate.now().minusYears(1)); int result = query.executeUpdate();In this example, we're deleting all employees whose hire date was more recent than a year ago. The result variable will contain the number of rows that were affected by the execution of this query. The org.hibernate Query class is part of the Hibernate package library.