/**
* 根据id删除普通用户
*/
public void deleteById(int id) {
System.out.println("deleteById");
//获得session
Session session = hibernateTemplate.getSessionFactory().openSession();
String str = "delete from ptuser where id="+id;
System.out.println(str);
//开启事务
session.beginTransaction();
//用原始的SQL操作,通过createSQLQuery写入SQL语句,通过executeUpdate执行操作
session.createSQLQuery(str).executeUpdate();
//提交事务
session.getTransaction().commit();
}
原文地址:http://yinzheyihao.blog.51cto.com/2100950/1587169