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

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);
   }
 }

你可能感兴趣的:(sql,Hibernate,HQL,session)