An alternative strategy is to create a method in the DAO and mark it with @Transactional. This method will perform a bulk update (for example, 500 ns). So you can have a method with code
@Transactional public void mybatchUpdateMethod(){ StatelessSession session = this.hibernateTemplate.getSessionFactory() .openStatelessSession(); Transaction transaction = null; Long entryCounter = 0L; PreparedStatement batchUpdate = null; try { transaction = session.beginTransaction(); batchUpdate = session.connection().prepareStatement(insertSql); for (BatchSnapshotEntry entry : entries) { entry.addEntry(batchUpdate); batchUpdate.addBatch(); if (++entryCounter == 500) {
Each time you call this method, it commits after 500 inserts / updates
source share