Say that class is named Donkey, and you wanted to update the
record in a table that Donkey is mapped to, that has a given primary key
and you wanted to update the column that is mapped to the property
size.
public void updateRecord(int primaryKey, String size) {
final Session s = HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();
try {
Query q = s.createQuery("UPDATE Donkey SET size = ? WHERE id = ?");
q.setString(0, size);
q.setInteger(0, primaryKey);
q.executeUpdate();
s.getTransaction().commit();
} catch (Exception e) {
s.getTransaction().rollback();
e.printStackTrace();
}
}