code: public String handleUpdateException(SQLException e, ItemData item) throws RepositoryException,
        InvalidItemStateException
     {
        StringBuilder message = new StringBuilder("[");
        message.append(containerName).append("] EDIT ").append(item.isNode() ? "NODE. " : "PROPERTY. ");
  
        String errMessage = e.getMessage();
        String itemInfo =
           item.getQPath().getAsString() + " " + item.getIdentifier()
              + (errMessage != null ? ". Cause >>>> " + errMessage : "");
  
        if (errMessage != null)
           // try detect error by foreign key names
           if (errMessage.toLowerCase().toUpperCase().indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
           {
              message.append("Property is not exists but the value is being created. Condition: property ID. ").append(
                 itemInfo);
              throw new RepositoryException(message.toString(), e);
           }
           else if (errMessage.toLowerCase().toUpperCase().indexOf(conn.JCR_PK_ITEM) >= 0)
           {
              message.append("Item already exists. Condition: ID. ").append(itemInfo);
              throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.UPDATED, e);
           }
  
        // try detect integrity violation
        RepositoryException ownException = null;
        try
        {
           ItemData me = conn.getItemData(item.getIdentifier());
           if (me != null)
           {
              // item already exists
              message.append("Item already exists. But update errors. ").append(itemInfo);
              ownException = new RepositoryException(message.toString(), e);
              throw ownException;
           }
        }
        catch (Exception ep)
        {
           // item not found or other things but error of item reading
           if (ownException != null)
              throw ownException;
        }
        message.append("Error of item update. ").append(itemInfo);
        throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.UPDATED, e);
     }
docs: Handle update Exceptions.
  
  @param e
  - an SQLException
  @param item
  - context ItemData
  @return String with error message
  @throws RepositoryException
  if <code>RepositoryException</code> should be thrown
  @throws InvalidItemStateException
  if <code>InvalidItemStateException</code> should be thrown