diff --git a/procedures/entityVersioning.sql b/procedures/entityVersioning.sql
index f339e1ea7943637114b9ce4b7253518da6294189..b474d0121130a1695d69616e1de4cc54468b5e64 100644
--- a/procedures/entityVersioning.sql
+++ b/procedures/entityVersioning.sql
@@ -434,74 +434,6 @@ BEGIN
 END //
 
 
-DROP PROCEDURE IF EXISTS setFileProperties //
-/**
- * Insert/Update file properties.
- *
- * If ENTITY_VERSIONING is enabled the old file properties are moved to
- * `archive_files`.
- *
- * Parameters
- * ----------
- * FileID
- *   The entity's id.
- * FileHash
- *   The SHA512 Hash of the file (or NULL for directories).
- * FileCheckedTimestamp
- *   The timestamp when the hash was last checked.
- * FileSize
- *   The byte size (or NULL for directories).
- * FilePath
- *   The path of the object.
- * FileMimeType
- *   The mimetype (use "inode/directory" for directories, use NULL for unknown)
- * FileStorageID
- *   The ID of the back-end file storage where this object is located.
- * FileKey
- *   The file storage key of this object.
- * FileParentID
- *   The entity id of the parent directory (or NULL).
- */
-CREATE PROCEDURE setFileProperties (
-    in FileID INT UNSIGNED,
-    in FilePath VARCHAR(5000),
-    in FileSize BIGINT UNSIGNED,
-    in FileHash VARCHAR(255),
-    in FileChecked BIGINT,
-    in FileMimeType VARBINARY(255),
-    in FileStorageId VARBINARY(255),
-    in FileKey VARBINARY(40000),
-    in FileParentID INT UNSIGNED,
-    in FileHashAlgo VARCHAR(255)
-)
-BEGIN
-    DECLARE IVersion INT UNSIGNED DEFAULT NULL;
-    IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-        SELECT max(e._iversion) INTO IVersion
-            FROM entity_version AS e
-            WHERE e.entity_id = FileID;
-
-        INSERT INTO archive_files (file_id, path, size, hash,
-                checked_timestamp, mimetype, file_storage_id, file_key,
-                _iversion, hash_algorithm)
-            SELECT file_id, path, size, hash, checked_timestamp, mimetype,
-                file_storage_id, file_key, IVersion AS _iversion, hash_algorithm
-            FROM files
-            WHERE file_id = FileID;
-    END IF;
-
-    DELETE FROM files WHERE file_id = FileID;
-
-    IF FilePath IS NOT NULL THEN
-        INSERT INTO files (file_id, path, size, hash, checked_timestamp,
-                mimetype, file_storage_id, file_key, hash_algorithm)
-            VALUES (FileID, FilePath, FileSize, unhex(FileHash), FileChecked,
-                FileMimeType, FileStorageId, FileKey, FileHashAlgo);
-    END IF;
-
-END //
-
-
 DROP PROCEDURE IF EXISTS retrieveQueryTemplateDef //
 
 /**
diff --git a/procedures/insertFSODescriptor.sql b/procedures/insertFSODescriptor.sql
index cdbd6bd18a8898f94ea7daeb2a9602bcc7410ac0..59d459fc8be83889675addf17119508eb59c45b7 100644
--- a/procedures/insertFSODescriptor.sql
+++ b/procedures/insertFSODescriptor.sql
@@ -61,7 +61,9 @@ CREATE PROCEDURE db_5_0.insertFSODescriptor(
     IN FileStorageId VARCHAR(255),
     IN FileKey VARCHAR(16000))
 insertFSODescriptorBody: BEGIN
+    DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
 
+    SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
     INSERT INTO files (
             file_id,
             hash,
@@ -73,7 +75,7 @@ insertFSODescriptorBody: BEGIN
             file_storage_id,
             file_key
             /*, parent_directory*/
-        ) VALUES (EntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey);
+        ) VALUES (InternalEntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey);
 
 END;
 //
diff --git a/procedures/retrieveFSODescriptorByPath.sql b/procedures/retrieveFSODescriptorByPath.sql
index 7a93a0a7dad17b01764d10ec49edd04d0532601b..c759a7d3b2ff3515f9c36805e2a6a4de11418efd 100644
--- a/procedures/retrieveFSODescriptorByPath.sql
+++ b/procedures/retrieveFSODescriptorByPath.sql
@@ -49,7 +49,7 @@ retrieveFSODescriptorByPathBody: BEGIN
 
     SELECT hash_algorithm AS FileHashAlgo,
             byPath as Param,
-            file_id AS FileId,
+            (SELECT id FROM entity_ids WHERE internal_id = file_id) AS FileId,
             path AS FilePath,
             size AS FileSize,
             hex(hash) AS FileHash,
diff --git a/procedures/setFileProperties.sql b/procedures/setFileProperties.sql
index e1efa3f4c200f37a4d1c1769ca6db1d31d27f62a..d9ebc10ab228a72c0ab47287bec2be1112b017ce 100644
--- a/procedures/setFileProperties.sql
+++ b/procedures/setFileProperties.sql
@@ -21,43 +21,59 @@
 DROP PROCEDURE IF EXISTS setFileProperties;
 DELIMITER //
 /**
- * Update file properties.
+ * Insert/Update file properties.
  *
  * If ENTITY_VERSIONING is enabled the old file properties are moved to
  * `archive_files`.
  *
  * Parameters
  * ----------
- * EntityID : VARCHAR(255)
- *   The file's id.
- * FilePath : TEXT
- *   Path of the file in the internal file system.  If NULL, an existing file
- *   entity is simply deleted.
- * FileSize : BIGINT UNSIGNED
- *   Size of the file in bytes.
- * FileHash : VARCHAR(255)
- *   A Sha512 Hash of the file.
+ * FileID
+ *   The entity's id.
+ * FileHash
+ *   The SHA512 Hash of the file (or NULL for directories).
+ * FileCheckedTimestamp
+ *   The timestamp when the hash was last checked.
+ * FileSize
+ *   The byte size (or NULL for directories).
+ * FilePath
+ *   The path of the object.
+ * FileMimeType
+ *   The mimetype (use "inode/directory" for directories, use NULL for unknown)
+ * FileStorageID
+ *   The ID of the back-end file storage where this object is located.
+ * FileKey
+ *   The file storage key of this object.
+ * FileParentID
+ *   The entity id of the parent directory (or NULL).
  */
 CREATE PROCEDURE setFileProperties (
-    in EntityID VARCHAR(255),
-    in FilePath TEXT,
+    in FileID INT UNSIGNED,
+    in FilePath VARCHAR(5000),
     in FileSize BIGINT UNSIGNED,
-    in FileHash VARCHAR(255)
+    in FileHash VARCHAR(255),
+    in FileChecked BIGINT,
+    in FileMimeType VARBINARY(255),
+    in FileStorageId VARBINARY(255),
+    in FileKey VARBINARY(40000),
+    in FileParentID INT UNSIGNED,
+    in FileHashAlgo VARCHAR(255)
 )
 BEGIN
-    DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
     DECLARE IVersion INT UNSIGNED DEFAULT NULL;
+    DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
 
-    SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
-
+    SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = FileID;
     IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
         SELECT max(e._iversion) INTO IVersion
             FROM entity_version AS e
             WHERE e.entity_id = InternalEntityID;
 
         INSERT INTO archive_files (file_id, path, size, hash,
-                _iversion)
-            SELECT file_id, path, size, hash, IVersion AS _iversion
+                checked_timestamp, mimetype, file_storage_id, file_key,
+                _iversion, hash_algorithm)
+            SELECT file_id, path, size, hash, checked_timestamp, mimetype,
+                file_storage_id, file_key, IVersion AS _iversion, hash_algorithm
             FROM files
             WHERE file_id = InternalEntityID;
     END IF;
@@ -65,8 +81,10 @@ BEGIN
     DELETE FROM files WHERE file_id = InternalEntityID;
 
     IF FilePath IS NOT NULL THEN
-        INSERT INTO files (file_id, path, size, hash)
-            VALUES (InternalEntityID, FilePath, FileSize, unhex(FileHash));
+        INSERT INTO files (file_id, path, size, hash, checked_timestamp,
+                mimetype, file_storage_id, file_key, hash_algorithm)
+            VALUES (InternalEntityID, FilePath, FileSize, unhex(FileHash), FileChecked,
+                FileMimeType, FileStorageId, FileKey, FileHashAlgo);
     END IF;
 
 END //