{"record":{"id":"528476a1b59a0388","repo":"pentaho/pentaho-kettle","slug":"unable-to-save-directory-dir-in-the-repository-528476","errorCode":null,"errorMessage":"Unable to save directory [dir] in the repository","messagePattern":"Unable to save directory \\[dir\\] in the repository","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDirectoryDelegate.java","lineNumber":302,"sourceCode":"      + quoteTable( KettleDatabaseRepository.TABLE_R_DIRECTORY ) + \" WHERE \"\n      + quote( KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT ) + \" = ? ORDER BY \"\n      + quote( KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME ), id_directory );\n  }\n\n  public void saveRepositoryDirectory( RepositoryDirectoryInterface dir ) throws KettleException {\n    try {\n      ObjectId id_directory_parent = null;\n      if ( dir.getParent() != null ) {\n        id_directory_parent = dir.getParent().getObjectId();\n      }\n\n      dir.setObjectId( insertDirectory( id_directory_parent, dir ) );\n\n      log.logDetailed( \"New id of directory = \" + dir.getObjectId() );\n\n      repository.commit();\n    } catch ( Exception e ) {\n      throw new KettleException( \"Unable to save directory [\" + dir + \"] in the repository\", e );\n    }\n  }\n\n  public void delRepositoryDirectory( RepositoryDirectoryInterface dir, boolean deleteNonEmptyFolder ) throws KettleException {\n    try {\n      if ( !deleteNonEmptyFolder ) {\n        String[] trans = repository.getTransformationNames( dir.getObjectId(), false ); // TODO : include or exclude\n                                                                                        // deleted objects?\n        String[] jobs = repository.getJobNames( dir.getObjectId(), false ); // TODO : include or exclude deleted\n                                                                            // objects?\n        ObjectId[] subDirectories = repository.getSubDirectoryIDs( dir.getObjectId() );\n        if ( trans.length == 0 && jobs.length == 0 && subDirectories.length == 0 ) {\n          repository.directoryDelegate.deleteDirectory( dir.getObjectId() );\n          repository.commit();\n        } else {\n          throw new KettleException( \"This directory is not empty!\" );\n        }\n      } else {","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDirectoryDelegate.java#L284-L320","documentation":"Wrapper KettleException thrown by saveRepositoryDirectory when any exception occurs while persisting a directory to the database (insert or update of the r_directory row, or the commit). The original exception is the cause; the message includes the directory's toString. This means the directory metadata was not saved and the transaction was not committed.","triggerScenarios":"Calling repository.saveRepositoryDirectory(dir, path, hide) / createRepositoryDirectory when insertDirectory/updateDirectory fails: DB connection error, constraint violation, oversized name, or the parent ObjectId no longer exists.","commonSituations":"Repository database read-only or out of space; parent directory deleted by another client between load and save; network interruption to the repository RDBMS; duplicate directory name at insert time.","solutions":["Inspect e.getCause() (KettleDatabaseException/SQLException) and fix the underlying DB issue","Verify the repository connection is alive and writable; reconnect and retry","Confirm the parent directory still exists before saving a new child","Check for name conflicts and DB constraint violations on r_directory"],"exampleFix":"// before\nrepository.saveRepositoryDirectory( dir, \"/new/path\", false );\n// after\ntry {\n  repository.saveRepositoryDirectory( dir, \"/new/path\", false );\n} catch ( KettleException e ) {\n  Throwable cause = e.getCause();\n  log.error( \"Directory save failed: \" + ( cause != null ? cause.getMessage() : e.getMessage() ) );\n}","handlingStrategy":"try-catch","validationCode":"// verify parent exists and connection is alive before saving\nRepositoryDirectoryInterface parent = repo.findDirectory( parentPath );\nif ( parent == null || parent.getObjectId() == null ) {\n  throw new IllegalStateException( \"Parent directory missing\" );\n}","typeGuard":null,"tryCatchPattern":"try {\n  repository.saveRepositoryDirectory( dir, path, hideInTree );\n} catch ( KettleException e ) {\n  Throwable cause = e.getCause();\n  if ( cause instanceof KettleDatabaseException ) { /* reconnect and retry */ }\n}","preventionTips":["Confirm the repository connection is writable before bulk directory creation","Refresh ObjectIds before save; another client may have deleted the parent","Check DB constraints and column lengths for directory names","Commit intentionally; avoid leaving transactions open around the save"],"tags":["database","directory-save","transaction"],"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"}