title: How to get sql exception from InvocationTargetException
body: <p>We are using Apache's openJPA. I am calling a delete method in a managed bean using Java reflection. The problem occurs when I try to delete a manged object that cannot be deleted because of a constraint violation. When I catch the InvocationTargetException and I retrieve the cause of the exception it states that no global transaction existence to roll back. </p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: No Global Transaction exists to rollback.
      at com.ibm.ws.tx.jta.UserTransactionImpl.rollback(UserTransactionImpl.java:349)
  </code></pre>
  
  <p>If I look farther down the stack trace I can see that a SQL exception was thrown because of a constraint violation.</p>
  
  <pre><code>---- Begin backtrace for Nested Throwables
  java.sql.SQLException: [SQL0532] Delete prevented by referential constraint CONSTRAINTNAME in LIBRARY.
  </code></pre>
  
  <p>Is there a way for me to get to the SQL exception so I can display a friendly message that the delete can not be performed because it is in use in another table.</p>
  
  <p>EDIT - Here is the code</p>
  
  <pre><code>public void deleteRowAction(Object list, DataTableTemplate template){
          System.out.println("Delete Row");
  
          try{
  
              Object bean = getManagedBean(template.getDataManagerName());
  
              Method methodDelete = getManagedBean(template.getDataManagerName()).getClass().getMethod(template.getDeleteMethod(), 
                      Class.forName(template.getTableList_rowItemClassName()));
  
              //Map&lt;String, String[]&gt; params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap();
  
              methodDelete.invoke(bean, list);
          }
          catch(PersistenceException pe){
              System.out.println("Persistence Exception Caught");
          }
          catch(NoSuchMethodException nsme){
              nsme.printStackTrace();
          }
          catch(InvocationTargetException ite){
  
              logException(ite);
              FacesMessage message = new FacesMessage(ite.getCause().getMessage());
              message.setSeverity(FacesMessage.SEVERITY_ERROR);
              FacesContext context = this.getFacesContext();
              context.addMessage(null, message);
          }
          catch(IllegalAccessException iae){
              iae.printStackTrace();
          }
          catch(ClassNotFoundException cnfe){
              cnfe.printStackTrace();
          }
      }
  </code></pre>