estoy haciendo un insert de datos con JPA y Hibernate, si los datos bienen correctos no tengo ningun problema, sin embargo si recibo datos errados me genera una excepción (y asi debe ser), el problema es que la excepcion que se permite capturar es EJBtransactionRolledBackExection
A continuación el trace del log (se elimino los registros no importantes)
2019-09-02 11:35:17,392 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-7) SQL Error: 2290, SQLState: 23000
2019-09-02 11:35:17,392 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-7) ORA-02290: restricción de control (RESTRICCION CHECK) violada
2019-09-02 11:35:17,392 INFO [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (default task-7) HHH000010: On release of batch it still contained JDBC statements
2019-09-02 11:35:17,393 WARN [com.arjuna.ats.arjuna] (default task-7) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffc0a83801:-6f00954f:5d6d3f3f:a0, org.wildfly.transaction.client.AbstractTransaction$AssociatingSynchronization@4df1da19 >: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02290: restricción de control (RESTRICCION CHECK) violada
2019-09-02 11:35:17,402 ERROR [org.jboss.as.ejb3.invocation] (default task-7) WFLYEJB0034: Invocación EJB falló en el componente ClaseJava para el método public void javax.ejb.EJBTransactionRolledbackException: Transaction rolled back
Caused by: javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02290: restricción de control (RESTRICCION CHECK) violada
2019-09-02 11:35:17,404 ERROR [io.undertow.request] (default task-7) UT005023: Exception handling request to /path/servicio/rest/: org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBTransactionRolledbackException: Transaction rolled back
Caused by: javax.ejb.EJBTransactionRolledbackException: Transaction rolled back
Caused by: javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02290: restricción de control (RESTRICCION CHECK) violada
Mi pregunta concreta es, ¿Como puedo hacer para capturar la excepción de PersistenceException
, ConstraintViolationException
o la de SQLIntegrityConstraintViolationException
? preferible la última ya que es la desencadena el resto.