gpt4 book ai didi

java - HibernateTemplate 更新查询

转载 作者:行者123 更新时间:2023-12-02 16:37:32 26 4
gpt4 key购买 nike

如何使用hibernate模板使用hql更新查询这是hql语句“update Login set empSmartId = 48750005”+“其中empPassword = 6328ef1675ddb7106eba8dc2661961d7”

使用 getHibernatetemplate()

当前代码:

 public class LoginDaoImp extends HibernateDaoSupport implements LoginDao { 
public boolean resetAttempt(Login login) {
try { login.setAttempt(0);
getHibernateTemplate().update(login);
return true;
} catch (Exception e) { e.printStackTrace(); }
return false; }
i can save whole pojo class above code work but i want to use where condition to update only hibernateTemplate to update the data

最佳答案

你会看起来像这样

public class LoginDaoImp extends HibernateDaoSupport implements LoginDao 
{
public boolean resetAttempt(Login login)
{
try
{
// you should create method for login to retrived based on password
//Remember getting login by password is not correct way, Instead you you should use primary key
//Getting persisted object of Login
Login persisted_login = getLoginByPassword(6328ef1675ddb7106eba8dc2661961d7);

//Setting value in persisted object of Login
persisted_login.setEmpSmartId (48750005);
getHibernateTemplate().update(persisted_login);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

关于java - HibernateTemplate 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15986484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com