{"record":{"id":"b1792ff506822732","repo":"pentaho/pentaho-kettle","slug":"unable-to-update-element-with-id-called-in-type","errorCode":null,"errorMessage":"Unable to update element with id '{}' called '{}' in type '{}'","messagePattern":"Unable to update element with id '(.+?)' called '(.+?)' in type '(.+?)'","errorType":"exception","errorClass":"MetaStoreException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java","lineNumber":412,"sourceCode":"    } 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    }\n  }\n\n  @Override\n  public IMetaStoreElementType newElementType( String namespace ) throws MetaStoreException {\n    return new KDBRMetaStoreElementType( delegate, namespace, null, null, null );\n  }\n\n  @Override\n  public IMetaStoreElement newElement() throws MetaStoreException {\n    return new KDBRMetaStoreElement();\n  }\n\n  @Override\n  public IMetaStoreElement newElement( IMetaStoreElementType elementType, String id, Object value ) throws MetaStoreException {\n    return new KDBRMetaStoreElement( delegate, elementType, id, value );\n  }","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/metastore/KettleDatabaseRepositoryMetaStore.java#L394-L430","documentation":"Thrown by updateElement when its delete-then-create implementation fails for any reason. The method deletes the old element by id, re-creates it, and commits; any exception (including wrapped errors 1131-1133) is rolled back and re-thrown as this MetaStoreException naming id, name and type.","triggerScenarios":"updateElement(namespace, elementType, elementId, element) where the internal deleteElement or createElement throws (duplicate name, missing type, bad id, DB failure), or repository.commit() fails.","commonSituations":"Renaming an element to a name that already exists (create-half collides); passing an elementId that no longer exists; DB connection loss between delete and create; concurrent updates to the same element.","solutions":["Ensure the new element name is unique within namespace/type before updating","Verify elementId and elementType are current (fetch fresh objects from the metastore)","Inspect getCause() to see whether delete or create failed and fix that specific issue","Retry after rollback — the whole update is atomic, so state is unchanged"],"exampleFix":"// before\nmetastore.updateElement(ns, type, id, element);\n// after\nString newName = element.getName();\nIMetaStoreElement dup = metastore.getElementByName(ns, type, newName);\nif (dup == null || id.equals(dup.getId())) {\n  metastore.updateElement(ns, type, id, element);\n}","handlingStrategy":"try-catch","validationCode":"IMetaStoreElement dup = metastore.getElementByName(namespace, elementType, element.getName());\nif (dup != null && !elementId.equals(dup.getId())) {\n  throw new IllegalStateException(\"Name collision on update: \" + element.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n  metastore.updateElement(namespace, elementType, elementId, element);\n} catch (MetaException | MetaStoreException e) {\n  LOG.error(\"Update of \" + elementId + \" failed, cause: \" + e.getCause(), e);\n  throw e;\n}","preventionTips":["Guarantee the new name is unique within namespace/type","Fetch fresh elementId/type before update (avoid stale handles)","Remember update is delete+create: avoid renaming onto an existing name","Rely on atomic rollback; safe to retry after fixing cause"],"tags":["metastore","update","transaction","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"}