pentaho/pentaho-kettle · error · MetaStoreException

The shared objects meta store already contains an element…

Error message

The shared objects meta store already contains an element with type name '{}' and element name '{}'

What it means

SharedObjectsMetaStore.createElement() first checks getElementByName() for an existing element and throws MetaStoreException if one with the same id/name already exists. Because shared objects are keyed by name, duplicates are not allowed. Note the message string omits the closing quote after the element name (formatting bug upstream).

Solutions

  1. Call getElementByName() first and update the existing element instead of creating a new one
  2. Rename the new element to a unique name before creating
  3. Delete the existing element via deleteElement, then re-create it

Example fix

// before
metaStore.createElement( ns, type, element );
// after
if ( metaStore.getElementByName( ns, type, element.getName() ) != null ) {
  element.setName( element.getName() + "-" + System.currentTimeMillis() );
}
metaStore.createElement( ns, type, element );
Defensive patterns

Strategy: validation

Validate before calling

IMetaStoreElement existing = metaStore.getElementByName( ns, elementType, element.getName() );
if ( existing != null ) {
  throw new IllegalStateException( "Element '" + element.getName() + "' already exists" );
}

Try / catch

try {
  metaStore.createElement( ns, type, element );
} catch ( MetaStoreException e ) {
  if ( e.getMessage() != null && e.getMessage().contains( "already contains an element" ) ) {
    metaStore.deleteElement( ns, type, element.getName() );
    metaStore.createElement( ns, type, element ); // upsert retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling createElement with an element whose id/name matches an element already present in the shared objects map, e.g. saving a DatabaseMeta with a name that already exists in shared objects.

Common situations: Re-importing database connections that already exist; scripts or UI flows that save connections without checking for name collisions; repeated test runs against the same shared.xml.

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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/shared/SharedObjectsMetaStore.java:162

    return null;
  }

  @Override
  public IMetaStoreElement getElementByName( String namespace, IMetaStoreElementType elementType, String name ) throws MetaStoreException {
    for ( IMetaStoreElement element : getElements( namespace, elementType ) ) {
      if ( ( element.getName().equalsIgnoreCase( name ) ) ) {
        return element;
      }
    }
    return null;
  }

  @Override
  public void createElement( String namespace, IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException, MetaStoreElementExistException {
    try {
      IMetaStoreElement exists = getElementByName( namespace, elementType, element.getId() );
      if ( exists != null ) {
        throw new MetaStoreException( "The shared objects meta store already contains an element with type name '"
          + elementType.getName() + "' and element name '" + element.getName() );
      }

      if ( elementType.getName().equals( databaseElementType.getName() ) ) {
        // convert the element to DatabaseMeta and store it in the shared objects file, then save the file
        //
        sharedObjects.storeObject( DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement( this, element ) );
        sharedObjects.saveToFile();
        return;
      }
      throw new MetaStoreException( "Storing elements with element type name '"
        + elementType.getName() + "' is not supported in the shared objects meta store" );
    } catch ( Exception e ) {
      throw new MetaStoreException( "Unexpected error creating an element in the shared objects meta store", e );
    }
  }

  @Override

View on GitHub (pinned to f3058517a1)