Using Spring Boot + Hibernate, I'm trying to bulk delete data using a nameQuery or nativeQuery. A few elements have constraint violations and Spring/Hibernate generates an entire rollback.
Is it possible to avoid the rollback? i.e. 100 records for deletion, 3 have constraints, so Hibernate generates a rollback for 100, but I need to rollback only 3 and still want to delete 97 elements. Right now I created a bad solution, I used a for loop and execute 100 sql queries.
On service layer:
@Transactional(noRollbackFor = {
SQLIntegrityConstraintViolationException.class,
PersistenceException.class,
ConstraintViolationException.class,
DataIntegrityViolationException.class })
public int deleteAll(String ids[]) {
call.dao.delete(ids)
}
On Hibernate layer:
delete(String ids[]) {
sql = "DELETE from mae1000 as x WHERE x.idccty in (:ids)";
int r = getCurrentSession().createNativeQuery(sql).setParameter("ids", Arrays.asList(ids)).executeUpdate();
}