1 Reply Latest reply on May 25, 2006 8:24 PM by voidhawc

    Unable to catch persist exception

      Hi,

      I'm currently developing an application where we want to handle all the exceptions within the application. When calling a persist on an entity which violates a unique constraint in the entity, I'm unable to catch it with the following code.

      try {
      // Use the Entity Manager to persist the given Object
      manager.persist(obj);

      return;
      }
      catch (IllegalArgumentException e) {
      throw new DataLayerException(0, "persist", "Illegal Argument", e.toString(), null, e);
      }
      catch (TransactionRequiredException e) {
      //throw new DataLayerException(1, "persist", "Transaction required", e.toString(), null, e);
      return;
      }
      catch (Throwable e) {
      throw new DataLayerException(DataLayerException.UNKNOWN_EXCEPTION, "persist", "Unknown", e.toString(), null, e);
      }finally {
      System.err.print("finally");
      }

      And it throws the following. I've trimmed the error down to the initial cause.

      10:05:46,185 INFO [STDOUT] Hibernate: select PROGRAM.nextval from dual
      10:05:46,185 INFO [STDOUT] finally
      10:05:46,201 INFO [STDOUT] Hibernate: insert into PROGRAM (PROGRAM_NAME, PROGRAM_PARENT, DESCRIPTION, USABLE, PERMITTING_PROGRAM_ID) values (?, ?, ?, ?, ?)
      10:05:46,232 WARN [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      10:05:46,232 ERROR [JDBCExceptionReporter] ORA-00001: unique constraint (PUBLIC.IDX_PROGRAM_NAME) violated

      10:05:46,232 WARN [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      10:05:46,232 ERROR [JDBCExceptionReporter] ORA-00001: unique constraint (PUBLIC.IDX_PROGRAM_NAME) violated

      Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (PUBLIC.IDX_PROGRAM_NAME) violated

      at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
      at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
      at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:487)
      at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
      at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
      ... 80 more


      Any help will be greatly appreciated.

      Thanks, Grant