如何在hql中更新boolean?

zsohkypk  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(451)

这是我的密码:

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

没用我也没有例外。

41ik7eoe

41ik7eoe1#

这是因为您尚未执行应执行的查询:

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

相关问题