日期:2014-05-20  浏览次数:20804 次

hql更新语句怎么搞的
————————createQuery里面的语句好像不正确--------------
public void updateInfo(String username, String repassword,String reemail){
 
  Session session=(Session) this.getSession();
  session.beginTransaction();
  Query query = session.createQuery("update User a set a.password =? set a.email=? where a.username =?");
  query.setString(0, repassword);
  query.setString(1, username);
  query.setString(2, reemail);
  query.executeUpdate();
  session.getTransaction().commit();
  }
}

------解决方案--------------------
TRy

update User a set a.password =? set a.email=? where a.username =?");

update User a , a.password =? , a.email=? where a.username =?");

------解决方案--------------------
update User a set a.password =? , a.email=? where a.username =?");

------解决方案--------------------
Java code

update User a set a.password =?, a.email=? where a.username =?

------解决方案--------------------
hibernate 里有封装好的更新

saveOrUpdate(实体类);【是通过是否有主键 例如:id 来判断是更新还是增加】

有主键值 就更新 没主键就增加一个