Java 在hibernate中删除

Java 在hibernate中删除,java,hibernate,Java,Hibernate,为对象运行delete方法时,不会从数据库中删除该对象 删除查询 @NamedQuery( name = "deleteAppointment", query = "delete Appointment t where t.id = : id" ), 删除约会的方法 public void deleteAppointment2(Integer appId){

为对象运行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();
        }
    }

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

您永远不会执行TypedQuery

您永远不会执行TypedQuery

添加的查询。executeUpdate();但它仍然没有delete@Robbie您也从未提交过事务。可能您也想在出现异常时显式回滚它。添加了query.executeUpdate();但它仍然没有delete@Robbie您也从不提交事务。可能您还希望在出现异常时显式回滚它。
   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();
        }
    }