1

How to use hql update query using hibernate template thi is the hql statement "update Login set empSmartId = 48750005" +" where empPassword = 6328ef1675ddb7106eba8dc2661961d7"

using getHibernatetemplate()

Current code:

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

ollo
  • 24,797
  • 14
  • 106
  • 155
matrix
  • 53
  • 2
  • 6
  • possible duplicate of [HibernateTemplate Update Query](http://stackoverflow.com/questions/15986484/hibernatetemplate-update-query) – Mikko Maunu Apr 13 '13 at 11:04

1 Answers1

1

HibernateDaoSupport will have a getSession() method which will return the hibernate session object for the DataSource configured. Using this session, you can say

Query updateQuery = getSession().createQuery("update Login l set l.empSmartId = :smartId where password = :password")
                   .setParameter("smartId", 48750005)
                   .setParameter("password", "6328ef1675ddb7106eba8dc2661961d7");
int noOfUpdatedRows = updateQuery.executeUpdate();
sanbhat
  • 17,522
  • 6
  • 48
  • 64