I'm using netbeans in an application that uses JPA+EclipseLink, and trying that when the "persist" method generates an error, I can catch it from the class and handle it. The error in question is due to duplicate key and for some reason, I can't catch it, as if the "catch" didn't work:
@Override
public void insertPtovta(Ptovta ptovta) throws ServletException {
try {
em.persist(ptovta);
} catch (Exception e) {
log.debug(e);
throw new ServletException("Ocurrio un Error en metodo buscaUsuario !", e);
}
}
This is part of the message that netbeans throws:
Warning: Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: ERROR: duplicate key violates uniqueness constraint "unq_ptovta_0" Detail: The key (idtype, letter, ptovta)=(2, A, 1) already exists. Error Code: 0 Call: INSERT INTO ptovta (COPIES, DESTINATION, PRINTS, LETTER, PTOVTA, ROW, TYPE, LAST, idtype) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) bind = > [9 parameters bound] Query: InsertObjectQuery(kompass.coopkit.model.Ptovta@1d5) at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
The error message is clearly visible in the glassfish log. Any idea how to catch it? Thank you very much in advance! Cheers