hibernate中用hql怎么执行delete的sql语句

来源:互联网 发布:炫舞房间源码 编辑:程序博客网 时间:2024/05/17 01:01
public void testDml(){   Session session = null;   Transaction tx = null;   try {    session = HibernateUtils.getSession();    tx = session.getTransaction();    session.beginTransaction();     Query query = session.createQuery("delete Student s where s.id=?");    query.setInteger(0, 1);    query.executeUpdate();    tx.commit();   } catch (HibernateException e) {    tx.rollback();    e.printStackTrace();   }finally{    HibernateUtils.closeSession(session);   } }
0 0
原创粉丝点击