Hibernate通过hql的方式进行删除,和更新不存在的数据,返回0
int hs = session.createQuery(hql).executeUpdate();
public int executeHql(final String hql)
/* */ throws SqlException
/* */ {
/* */ try
/* */ {
/* 1153 */ ((Integer)getHibernateTemplate().execute(
/* 1154 */ new HibernateCallback()
/* */ {
/* */ public Object doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException {
/* 1157 */ int hs = session.createQuery(hql).executeUpdate();
/* 1158 */ releaseSession(session);
/* 1159 */ return Integer.valueOf(hs);
/* */ }
/* */ })).intValue();
/* */ }
/* */ catch (Exception e) {
/* 1164 */ throw new SqlException(e.toString());
/* */ }
/* */ }
那么问题来了?当我们编程的时候,如果删除0条,我们认为也删除了。
但是如果是更新呢?如果只更新了0条数据,而你要更新的东西又很重要,必须要求真正做了更新操作。
那么返回0条记录,我们认为是更新失败了,所以要区别对待影响记录为0的情况。