Jesse James
Jesse James

Reputation: 1223

How to Update Multiple Fields at Once with HQL?

There's no problem with updating one field at a time:

hibernateTemplate.getSessionFactory().getCurrentSession().createQuery("UPDATE User set email='" + email+ "' where id='" + userId + "' ").executeUpdate();

But what if I want to update multiple fields at once? I added "AND" between the parameters but it didn't work:

hibernateTemplate.getSessionFactory().getCurrentSession().createQuery("UPDATE User set email='" + email+ "' AND firstName= '" + firstname + "' AND lastName= '"+lastname+"' AND password= '" + mdp + "' where id='" + userId + "' ").executeUpdate();

Could you please tell me how can I update many fields at once using HQL? Thanks.

Upvotes: 0

Views: 3064

Answers (1)

Dimitri Bosteels
Dimitri Bosteels

Reputation: 381

I guess this is based on SQL, then it is "," that you should put instead of "AND" behind the SET. Check this link.

Upvotes: 1

Related Questions