How to execute update hibernate query
How to run the this query
update User user
set user.status开发者_如何学JAVA = 1
where user.status = 0
and user.uiid = 12 or user.uiid =13 or user.uiid =14 or user.uiid =15
getHibernateTemplate()
I mean `getHibernateTemplate(). my query...
Please give me the example ..
Thanks
The object oriented way:
foreach(int id in ids)
{
User user = session.get<User>(id);
user.status = 1;
}
The hql way:
session
.createQuery("update User set status = :status where id in (:ids)");
.setInt("status", status)
.setParameterList("ids", ids)
.executeUpdate();
It depends on what you are doing in the whole transaction to say which way is better.
Use hibernateTemplate.find(HqlQuery)
See more varitions to find() method http://static.springsource.org/spring/docs/3.0.3.RELEASE/javadoc-api/org/springframework/orm/hibernate3/HibernateTemplate.html
精彩评论