{"record":{"id":"afa4cd3f0c201c03","repo":"pentaho/pentaho-kettle","slug":"failed-to-create-object-in-repository-object-0-already","errorCode":null,"errorMessage":"Failed to create object in repository. Object [{0}] 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/KettleDatabaseRepositoryPartitionSchemaDelegate.java","lineNumber":140,"sourceCode":"    RowMetaAndData row = getPartitionSchema( id_partition_schema );\n\n    partitionSchema.setName( row.getString( \"NAME\", null ) );\n\n    ObjectId[] pids = repository.getPartitionIDs( id_partition_schema );\n    for ( int i = 0; i < pids.length; i++ ) {\n      partitionSchema.getPartitionIDs().add( getPartition( pids[i] ).getString( \"PARTITION_ID\", null ) );\n    }\n\n    partitionSchema.setDynamicallyDefined( row.getBoolean( \"DYNAMIC_DEFINITION\", false ) );\n    partitionSchema.setNumberOfPartitionsPerSlave( row.getString( \"PARTITIONS_PER_SLAVE\", null ) );\n\n    return partitionSchema;\n  }\n\n  public synchronized ObjectId insertPartitionSchema( PartitionSchema partitionSchema ) throws KettleException {\n    if ( getPartitionSchemaID( partitionSchema.getName() ) != null ) {\n      // This partition schema name is already in use. Throw an exception.\n      throw new KettleObjectExistsException( \"Failed to create object in repository. Object [\"\n        + partitionSchema.getName() + \"] already exists.\" );\n    }\n\n    ObjectId id = repository.connectionDelegate.getNextPartitionSchemaID();\n\n    RowMetaAndData table = new RowMetaAndData();\n\n    table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_ID_PARTITION_SCHEMA ), id );\n    table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_NAME ),\n      partitionSchema.getName() );\n    table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_DYNAMIC_DEFINITION ),\n      partitionSchema.isDynamicallyDefined() );\n    table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_PARTITIONS_PER_SLAVE ),\n      partitionSchema.getNumberOfPartitionsPerSlave() );\n\n    repository.connectionDelegate.getDatabase().prepareInsert(\n      table.getRowMeta(), KettleDatabaseRepository.TABLE_R_PARTITION_SCHEMA );\n    repository.connectionDelegate.getDatabase().setValuesInsert( table );","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryPartitionSchemaDelegate.java#L122-L158","documentation":"insertPartitionSchema throws KettleObjectExistsException before generating an ID if a partition schema with the same name already exists in R_PARTITION_SCHEMA. This is the low-level guard preventing duplicate-named partition schemas in the repository.","triggerScenarios":"Calling insertPartitionSchema(partitionSchema) when getPartitionSchemaID(name) returns a non-null ID, i.e. the name is already taken. Reached via savePartitionSchema flows that decide to insert rather than update.","commonSituations":"Race between two clients inserting the same schema name concurrently; programmatic import loops that insert schemas without checking existence first; re-running migration scripts.","solutions":["Check existence first (getPartitionSchemaID) and update the existing object instead of inserting","Rename the schema to something unique before inserting","Catch KettleObjectExistsException and fall back to updatePartitionSchema on the existing ID","Serialize inserts (the method is synchronized) through a single writer process to avoid races"],"exampleFix":"// before\nObjectId id = delegate.insertPartitionSchema(schema);\n// after\nObjectId existingId = delegate.getPartitionSchemaID(schema.getName());\nObjectId id = (existingId != null)\n  ? existingId // reuse existing schema\n  : delegate.insertPartitionSchema(schema);","handlingStrategy":"validation","validationCode":"ObjectId existingId = delegate.getPartitionSchemaID(schema.getName());\nif (existingId != null) { /* update existing instead of inserting */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always upsert by name: check existence first, then insert or update","Avoid parallel inserts of identically named schemas across clients","Make import scripts idempotent","Catch KettleObjectExistsException and fall back to update"],"tags":["repository","duplicate","partition-schema","conflict"],"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"}