Further to my earlier posting, i tried producing error by inserting duplicate record . Unfortunately the Spring bean was not able to catch the Exception but the log file shows the following exception
Code:
2007-06-04 14:16:20,161 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ORA-00001: unique constraint (NAMS.NAMS_MANUFACTURER_UK) violated
>
2007-06-04 14:16:20,161 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - <Could not synchronize database state with session>
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (NAMS.NAMS_MANUFACTURER_UK) violated
Here is my Spring bean
Code:
public void createManufacturer(NamsManufacturer manuf) throws BaseException{
if (manuf.getStatus().equalsIgnoreCase("A")){
manuf.setStatus("A");
}else {
manuf.setStatus("I");
}
/* Moved to JSF Bean
manuf.setId(0);
manuf.setChangeDate(new Date());
Long changeUserId = getChangeUserByUserId();
System.out.println("In createManufacture UserId="+changeUserId);
NamsUser nu = namsUserDao.get(changeUserId);
manuf.setSource("N");
manuf.setNamsUser(nu);
*/
manuf.setSource("N");
try {
manufDao.persist(manuf);
} catch (DataIntegrityViolationException de) {
String msg = "Could not save Manufacturer, duplicate Manufacturer id " + de.getMessage();
this.logger.error(msg, de);
throw new DuplicateManufacturerIdException(msg, de);
} catch (Exception e) {
String msg = "Could not save Manufacturer " + e.toString();
this.logger.error(msg, e);
throw new BaseException(msg, e);
}
}