I have an oracle table with a unique contraint on a few fields. I am writing a piece of code to import data to that table from large excel files (thousands of rows usually). The whole import has to be in one transaction.
It might happen that in that thousands of rows there will be one or two rows duplicated. So I need to ignore SQLIntegrityConstraintViolationException and continue inserting all other rows. I just need to show message to the user that the rowNo 123 is a duplicate entry.
I am reading the excel file row by row (Apache POI event based), and each row is maped to hibernate POJO and saved right away:
public void saveRow( ExcelRow row) {
TableRow tableRow = new TableRow(row);
//some logic goes here
this.session.save(tableRow);
}
I tried to suround session.save with
try{
session.save(tableRow);
}catch(SQLIntegrityConstraintViolationException e)
{
//push the error message and continue
}
But Netbeans cries that exception SQLIntegrityConstraintViolationException is never thrown in body of corresponding try statement.
How to catch and ignore the integrity exception to continue processing data?
I would rather not have to execute another 10K selects to check if similar row exists.
SQLIntegrityConstraintViolationExceptionis wrapped in some other exception. Look for aorg.hibernate.exception.ConstraintViolationException