在应用到Hibernate框架的实际业务中,批量更新会经常被用到,具体的做法很多,但是有一种常用的做法如下代码所示: public void batchUpdate(Object[]params) { log.info("batchUpdate Torder with "+params); StringBuffer updateBuffer = new StringBuffer(); updateBuffer.append("update Torder set ispaid=?,"); updateBuffer.append("paymentDate=?,screenDate=?,"); updateBuffer.append("refundDate=?,chargeBackDate=?,"); updateBuffer.append("pendingDate=?,isdelivered=?,"); updateBuffer.append("deliveredDate=?,isUrgency=?,"); updateBuffer.append("urDegree=?,deliveredmark=?,"); updateBuffer.append("isinfofull=?,iscancel=?,"); updateBuffer.append("isaskrefund=?,processRefund=? "); updateBuffer.append("where formCode=?"); Type[]types = new Type[16]; types[0] = Hibernate.INTEGER; types[1] = Hibernate.TIMESTAMP; types[2] = Hibernate.TIMESTAMP; types[3] = Hibernate.TIMESTAMP; types[4] = Hibernate.TIMESTAMP; types[5] = Hibernate.TIMESTAMP; types[6] = Hibernate.INTEGER; types[7] = Hibernate.TIMESTAMP; types[8] = Hibernate.INTEGER; types[9] = Hibernate.SHORT; types[10] = Hibernate.INTEGER; types[11] = Hibernate.INTEGER; types[12] = Hibernate.INTEGER; types[13] = Hibernate.INTEGER; types[14] = Hibernate.INTEGER; types[15] = Hibernate.STRING; try { Query query = getSession().createQuery(updateBuffer.toString()); query.setParameters(params, types); int count = query.executeUpdate(); this.commit(); log.info(count+" has been batchUpdated successful!"); } catch (HibernateException e) { this.rollback(); log.error("batchUpdate failed", e); throw e; } }