Bulk updates are new to HQL with Hibernate 3, and deletes work differently in Hibernate 3 than they did in Hibernate 2. The Query interface now contains a method called executeUpdate() for executing HQL UPDATE or DELETE statements.
The UPDATE clause can be used to update one or more properties of an one or more objects. Following is the simple syntax of using UPDATE clause:
String hql ="UPDATE Employee set salary = :salary "+
"WHERE id = :employee_id"; Query query =session.createQuery(hql); query.setParameter("salary",1000); query.setParameter("employee_id",10); int result = query.executeUpdate(); System.out.println("Rows affected: "+ result); |