{"record":{"id":"50edcf01c19737d9","repo":"pentaho/pentaho-kettle","slug":"the-element-with-name-already-exists","errorCode":null,"errorMessage":"The element with name '{}' already exists","messagePattern":"The element with name '(.+?)' already exists","errorType":"exception","errorClass":"MetaStoreElementExistException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java","lineNumber":369,"sourceCode":"      }\n      RowMetaAndData elementRow = delegate.getElement( elementId );\n      if ( elementRow == null ) {\n        return null;\n      }\n\n      return delegate.parseElement( elementType, elementRow );\n    } catch ( Exception e ) {\n      throw new MetaStoreException( \"Unable to get element by name '\"\n        + name + \"' from namespace '\" + namespace + \"'\", e );\n    }\n  }\n\n  @Override\n  public void createElement( String namespace, IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException, MetaStoreElementExistException {\n    try {\n      IMetaStoreElement found = getElementByName( namespace, elementType, element.getName() );\n      if ( found != null ) {\n        throw new MetaStoreElementExistException( Arrays.asList( found ), \"The element with name '\"\n          + element.getName() + \"' already exists\" );\n      }\n\n      delegate.insertElement( elementType, element );\n      repository.commit();\n    } catch ( MetaStoreElementExistException e ) {\n      throw e;\n    } catch ( Exception e ) {\n      repository.rollback();\n      throw new MetaStoreException( \"Unable to create element with name '\"\n        + element.getName() + \"' of type '\" + elementType.getName() + \"'\", e );\n    }\n  }\n\n  @Override\n  public void deleteElement( String namespace, IMetaStoreElementType elementType, String elementId ) throws MetaStoreException {\n    try {\n      IMetaStoreElementType type = getElementTypeByName( namespace, elementType.getName() );","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java#L351-L387","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check existence first with getElementByName(namespace, elementType, element.getName()) and skip or update instead of creating","Catch MetaStoreElementExistException and treat it as idempotent success if the stored element is equivalent","Call deleteElement for the old element before re-creating, and verify the delete committed (repository.commit) before creating","Ensure updateElement is used with the correct elementId so its internal delete+create does not collide"],"exampleFix":"// before\nmetastore.createElement(namespace, elementType, element);\n// after\nif (metastore.getElementByName(namespace, elementType, element.getName()) == null) {\n  metastore.createElement(namespace, elementType, element);\n} else {\n  metastore.updateElement(namespace, elementType, element.getId(), element);\n}","handlingStrategy":"try-catch","validationCode":"if (metastore.getElementByName(namespace, elementType, element.getName()) != null) {\n  throw new IllegalStateException(\"Element already exists: \" + element.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n  metastore.createElement(namespace, elementType, element);\n} catch (MetaStoreElementExistException e) {\n  // treat as idempotent or update instead\n  metastore.updateElement(namespace, elementType, existingId, element);\n}","preventionTips":["Always check getElementByName before createElement","Use updateElement for re-runs instead of create","Make creation scripts idempotent","Serialize creation of identically-named elements across concurrent jobs"],"tags":["metastore","duplicate-element","repository","pentaho-kettle"],"backgroundTag":"file-already-exists","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}