Sagar Vaghela Sagar Vaghela -4 years ago 78
Java Question

what is difference between "update" method of Session class and "executeupdate" method of Query class in hibernate, when which method use?

what is difference between "update" method of Session class and "executeupdate" method of Query class in hibernate, when which method use?

Answer Source

In short: Session.update() is used to update a single mapped entity; with Query.executeupdate() you can perform custom delete/update statement (written is HQL or pure SQL) and get as result the updated/deleted entities count.
Which is the right method depends which is your need: with executeupdate() you can delete/update an arbitrary number of objects based on a query, with update() you can only update one single object at time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download