hibernate执行原生SQL
执行SQL更新
this.getHibernateTemplate().executeUpdate(new HibernateCallback(){ public Object doInHibernate(Session s) throws HibernateException,SQLException{String sql = "insert into xxx(xxx,xxx)";session.createQuery(sql).executeUpdate();});}
this.getHibernateTemplate.merge("TableName",entity);
public String delAddressByIds(final Long[] counts) { return String.valueOf(this.getHibernateTemplate().execute(new HibernateCallback() { public String doInHibernate(Session session) throws HibernateException, SQLException { String spars=""; for(int i=0;i<counts.length;i++){ spars=spars+counts[i]+","; } spars = spars.substring(0,spars.length()-1); String hql="update Store st set st.enabled=0 where st.id in ("+spars+")"; Query q = session.createQuery(hql); return q.executeUpdate()>0? Constant.successCode:Constant.deleteFailed; } })); }