首先要获得Session ,代码如下,记得要close
public boolean updateCommodityName(BusinessImage businessImage) {
try {
logger.info(businessImage.toString());
String hql="update BusinessImage b set b.commodityName='"+businessImage.getCommodityName()
+ "' where b.commodityNumber='"+businessImage.getCommodityNumber()+"'";
logger.info(hql);
Session session = getHibernateTemplate().getSessionFactory().openSession();
session.beginTransaction();
Query query = session.createQuery(hql);
logger.info(query.executeUpdate());
session.beginTransaction().commit();
session.close();
getHibernateTemplate().getSessionFactory().close();
return true;
} catch(Exception e) {
return false;
}
}