{"record":{"id":"1718f20921d19cba","repo":"pentaho/pentaho-kettle","slug":"unable-to-delete-element-with-id-of-type","errorCode":null,"errorMessage":"Unable to delete element with id '{}' of type '{}'","messagePattern":"Unable to delete element with id '(.+?)' of type '(.+?)'","errorType":"exception","errorClass":"MetaStoreException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java","lineNumber":396,"sourceCode":"      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() );\n      if ( type == null ) {\n        throw new MetaStoreException( \"Unable to find element type with name '\" + elementType.getName() + \"'\" );\n      }\n\n      delegate.deleteElement( new LongObjectId( new StringObjectId( elementId ) ) );\n      repository.commit();\n    } catch ( Exception e ) {\n      repository.rollback();\n      throw new MetaStoreException( \"Unable to delete element with id '\"\n        + elementId + \"' of type '\" + elementType.getName() + \"'\", e );\n    }\n  }\n\n  @Override\n  public void updateElement( String namespace, IMetaStoreElementType elementType, String elementId,\n    IMetaStoreElement element ) throws MetaStoreException {\n    try {\n      // This is a delete/insert operation\n      //\n      deleteElement( namespace, elementType, elementId );\n      createElement( namespace, elementType, element );\n      repository.commit();\n    } catch ( Exception e ) {\n      repository.rollback();\n      throw new MetaStoreException( \"Unable to update element with id '\"\n        + elementId + \"' called '\" + element.getName() + \"' in type '\" + elementType.getName() + \"'\", e );\n    }","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java#L378-L414","documentation":"Generic MetaStoreException wrapper from deleteElement: any failure after the type lookup — typically delegate.deleteElement on the given elementId or the subsequent commit — is wrapped with this message after repository.rollback(). The underlying cause is chained.","triggerScenarios":"delegate.deleteElement(new LongObjectId(new StringObjectId(elementId))) fails because the elementId does not exist, is malformed, or the DB write/commit throws; deleteElement also runs inside updateElement, so a bad elementId surfaces here.","commonSituations":"Deleting with an elementId from a different type/namespace; stale IDs after the element was already deleted; DB connectivity loss during the delete transaction.","solutions":["Verify the element exists (getElementById / getElementByName) before deleting","Confirm the elementId belongs to the given elementType and namespace","Check the cause for the real DB error and fix connectivity/constraint issues","Re-run after rollback; the transaction leaves state unchanged"],"exampleFix":"// before\nmetastore.deleteElement(namespace, elementType, elementId);\n// after\nif (metastore.getElementById(namespace, elementType, elementId) != null) {\n  metastore.deleteElement(namespace, elementType, elementId);\n}","handlingStrategy":"try-catch","validationCode":"if (metastore.getElementById(namespace, elementType, elementId) == null) {\n  throw new IllegalStateException(\"Element not found: \" + elementId);\n}","typeGuard":null,"tryCatchPattern":"try {\n  metastore.deleteElement(namespace, elementType, elementId);\n} catch (MetaStoreException e) {\n  if (metastore.getElementById(namespace, elementType, elementId) == null) {\n    // already gone; idempotent success\n  } else throw e;\n}","preventionTips":["Verify element existence before delete","Use IDs freshly fetched from the same namespace/type","Treat not-found as success for idempotent deletes","Check getCause() for DB-level failures"],"tags":["metastore","delete","database","rollback"],"backgroundTag":"database-write-failed","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"}