{"record":{"id":"9a077cd281fcd9d3","repo":"pentaho/pentaho-kettle","slug":"error-saving-database-connection-or-one-of-its-attributes-to","errorCode":null,"errorMessage":"Error saving database connection or one of its attributes to the repository.","messagePattern":"Error saving database connection or one of its attributes to the repository\\.","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java","lineNumber":195,"sourceCode":"      } else {\n        // --> found entry with the same name...\n\n        // Update the note...\n        updateDatabase(\n          databaseMeta.getObjectId(), databaseMeta.getName(), databaseMeta.getPluginId(), DatabaseMeta\n            .getAccessTypeDesc( databaseMeta.getAccessType() ), databaseMeta.getHostname(), databaseMeta\n            .getDatabaseName(), databaseMeta.getDatabasePortNumberString(), databaseMeta.getUsername(),\n          databaseMeta.getPassword(), databaseMeta.getServername(), databaseMeta.getDataTablespace(),\n          databaseMeta.getIndexTablespace() );\n      }\n\n      // For the extra attributes, just delete them and re-add them.\n      delDatabaseAttributes( databaseMeta.getObjectId() );\n\n      // OK, now get a list of all the attributes set on the database connection...\n      insertDatabaseAttributes( databaseMeta.getObjectId(), databaseMeta.getAttributes() );\n    } catch ( KettleDatabaseException dbe ) {\n      throw new KettleException(\n        \"Error saving database connection or one of its attributes to the repository.\", dbe );\n    }\n  }\n\n  public synchronized ObjectId insertDatabase( String name, String type, String access, String host,\n    String dbname, String port, String user, String pass, String servername, String data_tablespace,\n    String index_tablespace ) throws KettleException {\n\n    ObjectId id = repository.connectionDelegate.getNextDatabaseID();\n\n    ObjectId id_database_type = getDatabaseTypeID( type );\n    if ( id_database_type == null ) {\n      // New support database type: add it!\n\n      id_database_type = repository.connectionDelegate.getNextDatabaseTypeID();\n\n      String tablename = KettleDatabaseRepository.TABLE_R_DATABASE_TYPE;\n      RowMetaInterface tableMeta = new RowMeta();","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java#L177-L213","documentation":"Wraps a KettleDatabaseException thrown while persisting a DatabaseMeta and its attributes to the repository (insert/update of R_DATABASE plus delete/re-insert of its attribute rows). The save is not applied and the cause carries the database-level error.","triggerScenarios":"Calling saveDatabaseMeta(databaseMeta) when any insert/update of R_DATABASE, or delDatabaseAttributes/insertDatabaseAttributes, throws: constraint violation, SQL error, or lost connection.","commonSituations":"Saving a connection with a name that conflicts with an existing entry; repository DB read-only or quota exceeded; connection dropped mid-save; duplicate attribute rows from a previously failed save.","solutions":["Inspect the wrapped KettleDatabaseException for the failing statement","Ensure the connection name is unique in R_DATABASE or update the existing entry instead of inserting","Verify the repository DB is writable and the session connection is healthy","Clean duplicate/orphan R_DATABASE_ATTRIBUTE rows for the connection id, then retry"],"exampleFix":"// before\nrep.save(repoMeta, \"my-connection\"); // may duplicate/conflict\n// after: reuse existing id if the connection already exists\nObjectId existing = databaseDelegate.getDatabaseID(\"my-connection\");\ndatabaseMeta.setObjectId(existing); // null => insert, otherwise update\ndatabaseDelegate.saveDatabaseMeta(databaseMeta);","handlingStrategy":"validation","validationCode":"// ensure name uniqueness before saving\nPreparedStatement ps = conn.prepareStatement(\"SELECT COUNT(*) FROM R_DATABASE WHERE NAME = ?\");\nps.setString(1, databaseMeta.getName());\nif (rsCount(ps) > 0) { databaseMeta.setObjectId(databaseDelegate.getDatabaseID(databaseMeta.getName())); }","typeGuard":null,"tryCatchPattern":"try {\n  delegate.saveDatabaseMeta(databaseMeta);\n} catch (KettleException e) {\n  log.error(\"Save of database connection failed\", e.getCause());\n  // check constraints, writability, then retry\n}","preventionTips":["Use unique connection names across environments","Verify repository DB is writable before bulk operations","Clean orphaned attribute rows after failed saves"],"tags":["database","repository","save","database-meta"],"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"}