我要更新用户的WHERE
:
这是我的问题:
password
但没有变化!
更新
这也行不通:
@Transactional
public void resetPassInDB(String userEmail, String newPass) {
Query query = userDao.getSession().createQuery("update User u set u.password = :password where u.email = :email");
query.setParameter("password", newPass);
query.setParameter("email", userEmail);
int result = query.executeUpdate(); // is 0
}
在控制台中:
Query query = userDao.getSession().createQuery("from User where email= :email");
query.setParameter("email", userEmail);
User user = (User) query.list().get(0);
user.setPassword(newPass);
userDao.getSession().update(user);
UPDATE2
Hibernate: select user0_.id as id1_2_, user0_.email as email2_2_, user0_.password as password3_2_, user0_.username as username4_2_ from User user0_ where user0_.email=?
控制台:
@Transactional
public void resetPassInDB(String userEmail, String newPass) {
Query query = userDao.getSession().createQuery("from User where email= :email");
query.setParameter("email", userEmail);
User user = (User) query.list().get(0);
System.out.println("retrieved user: " + user);
user.setPassword(newPass);
userDao.getSession().update(user);
System.out.println("updated user: " + user);
}
但Hibernate: select user0_.id as id1_2_, user0_.email as email2_2_, user0_.password as password3_2_, user0_.username as username4_2_ from User user0_ where user0_.email=?
retrieved user: username: aaaa, password: llkk, email: abc@gmail.com
updated user: username: aaaa, password: vvbb, email: abc@gmail.com
表中没有任何变化!