在休眠状态下删除

时间:2019-05-04 15:30:47

标签: java hibernate

运行对象的delete方法时,不会从数据库中删除它

删除查询

 @NamedQuery(
                        name = "deleteAppointment",
                        query = "delete Appointment t where t.id = : id"
                ),

删除约会的方法

   public void deleteAppointment2(Integer appId){
        Session session = factory.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            TypedQuery query = session.getNamedQuery("deleteAppointment");
             query.setParameter("id", appId);
             query.executeUpdate();
        }catch (HibernateException e){
            e.printStackTrace();
        }
    }

但是,当我运行该方法时,它不会删除约会

1 个答案:

答案 0 :(得分:2)

您从不执行TypedQuery