Using Spring 2.2.5 with Spring Data / JPA / Hibernate.
When using the CrudRepository with either CrudRepository#saveAll()
or a loop structure with individual CrudRepository#save()
, it seems impossible to tell which of the elements violates a constraint.
Assuming this method:
@Transactional
public void storeAll(Collection<Attribute> attributes) {
repository.saveAll(attributes);
}
The returned DataIntegrityViolationException
with a nested hibernate ContraintViolationException
is being thrown. There seem to be no references to the entity in said exceptions.
Using a loop doesn't work either:
@Transactional
public void storeAll(Collection<Attribute> attributes) {
for(Attribute attribute : attributes){
try{
repository.save(attribute);
}catch (Exception e){
///
}
}
}
The exception inside the loop isn't being catched (the save method doesn't seem to throw anything). Instead, it's thrown when returning from the method. Maybe due to optimization of some sort?