All pastes #616665 Raw Edit

Untitled

public text v1 · immutable
·published 2007-07-12 19:25 UTC
rendered paste body
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();
    }
}