{"record":{"id":"1a7d2e2ba9809683","repo":"pentaho/pentaho-kettle","slug":"failed-to-create-object-in-repository-object-name-already","errorCode":null,"errorMessage":"Failed to create object in repository. Object [{name}] already exists.","messagePattern":"Failed to create object in repository\\. Object \\[(.+?)\\] already exists\\.","errorType":"exception","errorClass":"KettleObjectExistsException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryClusterSchemaDelegate.java","lineNumber":148,"sourceCode":"      if ( slaveServer.getObjectId() == null ) {\n        // oops, not yet saved!\n\n        repository.save( slaveServer, versionComment, null, id_transformation, isUsedByTransformation, overwrite );\n      }\n      repository.insertClusterSlave( clusterSchema, slaveServer );\n    }\n\n    // Save a link to the transformation to keep track of the use of this cluster schema\n    // Only save it if it's really used by the transformation\n    if ( isUsedByTransformation ) {\n      repository.insertTransformationCluster( id_transformation, clusterSchema.getObjectId() );\n    }\n  }\n\n  private synchronized ObjectId insertCluster( ClusterSchema clusterSchema ) throws KettleException {\n    if ( getClusterID( clusterSchema.getName() ) != null ) {\n      // This cluster schema name is already in use. Throw an exception.\n      throw new KettleObjectExistsException( \"Failed to create object in repository. Object [\"\n        + clusterSchema.getName() + \"] already exists.\" );\n    }\n\n    ObjectId id = repository.connectionDelegate.getNextClusterID();\n\n    RowMetaAndData table = new RowMetaAndData();\n\n    table.addValue( new ValueMetaInteger(\n      KettleDatabaseRepository.FIELD_CLUSTER_ID_CLUSTER ), id );\n    table.addValue(\n      new ValueMetaString( KettleDatabaseRepository.FIELD_CLUSTER_NAME ),\n      clusterSchema.getName() );\n    table.addValue( new ValueMetaString(\n      KettleDatabaseRepository.FIELD_CLUSTER_BASE_PORT ), clusterSchema\n      .getBasePort() );\n    table\n      .addValue(\n        new ValueMetaString(","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryClusterSchemaDelegate.java#L130-L166","documentation":"KettleObjectExistsException thrown by the private insertCluster method when the cluster schema name is already present in the repository at insert time. It is a last-resort guard inside saveClusterSchema: even if the higher-level collision check passed, the insert re-verifies uniqueness before generating a new id. This keeps repository names unique under concurrency.","triggerScenarios":"insertCluster invoked (via saveClusterSchema) while another thread/session has just created a cluster schema with the same name, so getClusterID(name) returns non-null right before insert.","commonSituations":"Two developers or two import jobs inserting identically-named cluster schemas concurrently; race between the duplicate check and the insert.","solutions":["Retry the save operation, which will now detect the existing object and take the update path","Use repository.deleteClusterSchema on the conflicting id if the new object should replace it","Rename the cluster schema to a unique name before saving","Serialize repository writes (the method is synchronized; avoid bypassing saveClusterSchema)"],"exampleFix":"// before\nObjectId id = repository.save(clusterSchema, \"v1\", new Date(), false); // may race\n\n// after\ntry {\n  id = repository.save(clusterSchema, \"v1\", new Date(), true);\n} catch (KettleObjectExistsException e) {\n  clusterSchema.setName(clusterSchema.getName() + \"-\" + System.currentTimeMillis());\n  id = repository.save(clusterSchema, \"v1\", new Date(), false);\n}","handlingStrategy":"retry","validationCode":"if (repository.getClusterSchemaID(clusterSchema.getName()) != null) { clusterSchema.setName(clusterSchema.getName() + \"_\" + UUID.randomUUID()); }","typeGuard":"boolean insertable = repository.getClusterSchemaID(name) == null;","tryCatchPattern":"try { repository.save(cs, label, date, false); } catch (KettleObjectExistsException e) { cs.setName(uniqueName()); repository.save(cs, label, date, false); }","preventionTips":["Serialize writes to the same repository from concurrent jobs","Generate unique names with suffixes when auto-importing","Retry once with rename on collision","Avoid direct delegate calls; use repository-level save with overwrite flags"],"tags":["repository","cluster-schema","race-condition"],"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"}