5 Replies Latest reply on Apr 11, 2010 1:27 AM by jaikiran pai

    The cause exception lost in the exception chain

    Dave Chen Master

      public void commit() {
        try {
           userTransaction.commit();
         } catch (Throwable t) {
           t.printStackTrace();
         }
      }

      In case of org.hibernate.exception.ConstraintViolationException, on the terminal the error message:

       

      javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not delete: [mypackage.Foo#1]
              at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
              at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513)
              at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:269)
              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89)
              at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1423)
              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
              at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)
      ...
      Caused by: org.hibernate.exception.ConstraintViolationException: could not delete: [package.Foo#1]
              at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
              at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
              at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2569)
              at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2725)
              at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
              at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
              at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
              ... 58 more
      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails ...
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
              at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
              at com.mysql.jdbc.Util.getInstance(Util.java:381)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
              at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
              at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
              at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
              at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)
              at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:874)
              at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365)
              at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
              ... 68 more

      but the caught Throwable is javax.transaction.RollbackException, it did not have ConstraintViolation information. We like to show the constraint violation information to users. How to get the real cuase of the exception?  we use JBOSS 5.1.0GA. Thanks!

      Dave