{"record":{"id":"78514d3aa1bbf16f","repo":"pentaho/pentaho-kettle","slug":"can-not-create-element-type-with-id-elementtype-id-because","errorCode":null,"errorMessage":"Can not create element type with id '${elementType.id}' because it already exists","messagePattern":"Can not create element type with id '(.+?)' because it already exists","errorType":"exception","errorClass":"MetaStoreElementTypeExistsException","httpStatus":null,"severity":"error","filePath":"plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/metastore/PurRepositoryMetaStore.java","lineNumber":149,"sourceCode":"  public List<String> getNamespaces() throws MetaStoreException {\n    List<String> namespaces = new ArrayList<String>();\n    List<RepositoryFile> children = getChildren( namespacesFolder.getId() );\n    for ( RepositoryFile child : children ) {\n      namespaces.add( child.getName() );\n    }\n    return namespaces;\n  }\n\n  // The element types\n\n  @Override\n  public void createElementType( String namespace, IMetaStoreElementType elementType ) throws MetaStoreException {\n\n    RepositoryFile namespaceFile = validateNamespace( namespace );\n\n    IMetaStoreElementType existingType = getElementTypeByName( namespace, elementType.getName() );\n    if ( existingType != null ) {\n      throw new MetaStoreElementTypeExistsException( Collections.singletonList( existingType ),\n          \"Can not create element type with id '\" + elementType.getId() + \"' because it already exists\" );\n    }\n\n    RepositoryFile elementTypeFile =\n        new RepositoryFile.Builder( elementType.getName() ).folder( true ).versioned( false ).build();\n\n    RepositoryFile folder = pur.createFolder( namespaceFile.getId(), elementTypeFile, null );\n    elementType.setId( folder.getId().toString() );\n\n    // In this folder there is a hidden file which contains the description\n    // and the other future properties of the element type\n    //\n    RepositoryFile detailsFile =\n        new RepositoryFile.Builder( ELEMENT_TYPE_DETAILS_FILENAME ).folder( false ).title(\n            ELEMENT_TYPE_DETAILS_FILENAME ).description( elementType.getDescription() ).hidden( true ).build();\n\n    DataNode dataNode = getElementTypeDataNode( elementType );\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/metastore/PurRepositoryMetaStore.java#L131-L167","documentation":"Thrown by PurRepositoryMetaStore.createElementType() when an element type with the same name already exists in the namespace (getElementTypeByName returns non-null). It is a MetaStoreElementTypeExistsException including the existing type; note the message text references the new type's id even though the collision is name-based.","triggerScenarios":"Calling createElementType(namespace, elementType) when a type of the same name already exists under /etc/metastore/<namespace> — re-running registration code, or another client created the type concurrently.","commonSituations":"Plugin initialization that registers element types on every start; migration scripts run twice; two PDI instances open against the same repository.","solutions":["Look up the type with getElementTypeByName first and reuse/update it instead of creating","Catch MetaStoreElementTypeExistsException and fall back to the existing type","Ensure idempotent initialization logic"],"exampleFix":"// before\nmetaStore.createElementType( ns, elementType );\n// after\nIMetaStoreElementType existing = metaStore.getElementTypeByName( ns, elementType.getName() );\nif ( existing == null ) {\n  metaStore.createElementType( ns, elementType );\n} else {\n  elementType.setId( existing.getId() );\n}","handlingStrategy":"validation","validationCode":"IMetaStoreElementType existing = metaStore.getElementTypeByName( ns, elementType.getName() );\nif ( existing == null ) { metaStore.createElementType( ns, elementType ); } else { elementType.setId( existing.getId() ); }","typeGuard":null,"tryCatchPattern":"try { metaStore.createElementType( ns, t ); } catch ( MetaStoreElementTypeExistsException e ) { t.setId( e.getElementType().getId() ); }","preventionTips":["Register element types only once (guard initialization)","Reuse the existing type instead of re-creating","Serialize type registration when multiple clients start together"],"tags":["metastore","element-type","duplicate"],"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"}