pentaho/pentaho-kettle · error · MetaStoreElementExistException

The element with name

Error message

The element with name '{}' already exists

What it means

Thrown by KettleDatabaseRepositoryMetaStore.createElement when an element with the same name already exists in the given namespace/element type. The repository checks getElementByName first and throws MetaStoreElementExistException so callers can detect duplicates distinctly from other failures. It is a deliberate uniqueness guard, not an unexpected failure.

Solutions

  1. Check existence first with getElementByName(namespace, elementType, element.getName()) and skip or update instead of creating
  2. Catch MetaStoreElementExistException and treat it as idempotent success if the stored element is equivalent
  3. Call deleteElement for the old element before re-creating, and verify the delete committed (repository.commit) before creating
  4. Ensure updateElement is used with the correct elementId so its internal delete+create does not collide

Example fix

// before
metastore.createElement(namespace, elementType, element);
// after
if (metastore.getElementByName(namespace, elementType, element.getName()) == null) {
  metastore.createElement(namespace, elementType, element);
} else {
  metastore.updateElement(namespace, elementType, element.getId(), element);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (metastore.getElementByName(namespace, elementType, element.getName()) != null) {
  throw new IllegalStateException("Element already exists: " + element.getName());
}

Try / catch

try {
  metastore.createElement(namespace, elementType, element);
} catch (MetaStoreElementExistException e) {
  // treat as idempotent or update instead
  metastore.updateElement(namespace, elementType, existingId, element);
}

Prevention

When it happens

Trigger: Calling createElement(namespace, elementType, element) when an element named element.getName() already exists under that namespace and element type; also occurs inside updateElement, which implements update as deleteElement+createElement and re-throws the duplicate error if the delete path left the old element in place.

Common situations: Re-running an import/migration script that creates metastore elements (e.g. named kettle transforms or job entries) without checking existence first; concurrent jobs creating the same named element; updateElement called with a stale elementId whose delete silently failed.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/50edcf01c19737d9. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java:369

      }
      RowMetaAndData elementRow = delegate.getElement( elementId );
      if ( elementRow == null ) {
        return null;
      }

      return delegate.parseElement( elementType, elementRow );
    } catch ( Exception e ) {
      throw new MetaStoreException( "Unable to get element by name '"
        + name + "' from namespace '" + namespace + "'", e );
    }
  }

  @Override
  public void createElement( String namespace, IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException, MetaStoreElementExistException {
    try {
      IMetaStoreElement found = getElementByName( namespace, elementType, element.getName() );
      if ( found != null ) {
        throw new MetaStoreElementExistException( Arrays.asList( found ), "The element with name '"
          + element.getName() + "' already exists" );
      }

      delegate.insertElement( elementType, element );
      repository.commit();
    } catch ( MetaStoreElementExistException e ) {
      throw e;
    } catch ( Exception e ) {
      repository.rollback();
      throw new MetaStoreException( "Unable to create element with name '"
        + element.getName() + "' of type '" + elementType.getName() + "'", e );
    }
  }

  @Override
  public void deleteElement( String namespace, IMetaStoreElementType elementType, String elementId ) throws MetaStoreException {
    try {
      IMetaStoreElementType type = getElementTypeByName( namespace, elementType.getName() );

View on GitHub (pinned to f3058517a1)