您需要开始并提交事务。
Transaction transaction = session.beginTransaction();try { // your pre String hql = "delete from Vote where uid= :uid AND pid= :pid"; Query query = session.createQuery(hql); System.out.println(user.getUid() + " and pid: " + pid); query.setString("uid", user.getUid()); query.setInteger("pid", pid); System.out.println(query.executeUpdate()); // your pre end transaction.commit();} catch (Throwable t) { transaction.rollback(); throw t;}还可能需要关闭会话,然后更改才能在数据库中可见。



