pentaho/pentaho-kettle · error · MetaStoreElementTypeExistsException

Can not create element type with id…

Error message

Can not create element type with id ''+elementType.getId()+'' because it already exists

What it means

Thrown by createElementType when an element type with the same name already exists in the target namespace of the Kettle database repository metastore. The metastore enforces unique element type names per namespace, so a duplicate insert is rejected with MetaStoreElementTypeExistsException, which also carries the conflicting existing type. This is a deliberate guard, not a corruption.

Solutions

  1. Check existence first: call getElementTypeByName(namespace, name) and reuse or updateElementType the existing type instead of createElementType.
  2. Catch MetaStoreElementTypeExistsException and treat it as idempotent (log and continue, or delete the existing type then recreate).
  3. If the old type is obsolete, call deleteElementType (after removing dependent elements) and then createElementType again.
  4. Verify you are using the intended namespace — a typo may collide with an unrelated existing type.

Example fix

// before
metastore.createElementType(namespace, newType);

// after
IMetaStoreElementType existing = metastore.getElementTypeByName(namespace, newType.getName());
if (existing == null) {
  metastore.createElementType(namespace, newType);
} else {
  newType.setId(existing.getId());
  metastore.updateElementType(namespace, newType);
}
Defensive patterns

Strategy: validation

Validate before calling

if (metastore.getElementTypeByName(namespace, elementType.getName()) != null) {
  throw new IllegalStateException("Element type '" + elementType.getName() + "' already exists in namespace");
}
metastore.createElementType(namespace, elementType);

Try / catch

try {
  metastore.createElementType(namespace, elementType);
} catch (MetaStoreElementTypeExistsException e) {
  IMetaStoreElementType existing = e.getExistingElementTypes().get(0);
  elementType.setId(existing.getId());
  metastore.updateElementType(namespace, elementType);
}

Prevention

When it happens

Trigger: Calling KettleDatabaseRepositoryMetaStore.createElementType(namespace, elementType) when getElementTypeByName(namespace, elementType.getName()) returns a non-null existing type — i.e. the name was already registered in that namespace (elementTypeId may even be null/unset on the new object).

Common situations: Re-running an initialization/bootstrap routine that registers metastore element types (e.g. for_named_types used by Kafka, Avro, streaming tools) without checking existence first; running the same job against a repository that was already populated; creating the element type in the wrong namespace where a same-named type already exists.

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/c62be54a168d2c2a. Report an issue: GitHub.

Appendix: source

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

      return delegate.getNamespaceId( namespace ) != null;
    } catch ( Exception e ) {
      throw new MetaStoreException( "Unable to verify if namespace '" + namespace + "' exists.", e );
    }
  }

  // Handle the element types

  public void createElementType( String namespace, IMetaStoreElementType elementType ) throws MetaStoreException,
    MetaStoreElementTypeExistsException {
    try {

      ObjectId namespaceId = delegate.verifyNamespace( namespace );

      // See if the element already exists in this namespace
      //
      IMetaStoreElementType existingType = getElementTypeByName( namespace, elementType.getName() );
      if ( existingType != null ) {
        throw new MetaStoreElementTypeExistsException(
          Arrays.asList( existingType ), "Can not create element type with id '"
            + elementType.getId() + "' because it already exists" );
      }

      KDBRMetaStoreElementType newElementType =
        new KDBRMetaStoreElementType( delegate, namespace, namespaceId, elementType.getName(), elementType
          .getDescription() );
      newElementType.save();
      elementType.setId( newElementType.getId() );
      repository.commit();
    } catch ( MetaStoreElementTypeExistsException e ) {
      throw e;
    } catch ( MetaStoreException e ) {
      repository.rollback();
      throw e;
    } catch ( Exception e ) {
      repository.rollback();
      throw new MetaStoreException( e );

View on GitHub (pinned to f3058517a1)