如何更新hql中的布尔值?

How to update boolean in hql?

这是我的代码:

public static boolean alterReservation(int reservationId) {
    try {
        Session session = getSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();

        Query query = session
                        .createQuery("update Reservation  set realized = true where id= :reservationId");
        query.setParameter("reservationId", reservationId);
        transaction.commit();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
update Reservation  set realized = true where id= :reservationId

不起作用我没有例外。

那是因为你没有执行你应该执行的查询:

.....
  Query query = session.createQuery("update Reservation  set realized = true where id= :reservationId");
  query.setParameter("reservationId", reservationId);
  query.executeUpdate();  <<<<<<<<<<
.....