diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java index b91ae0c96b8..fdf49929ac0 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DestroyDatasetCommand.java @@ -53,12 +53,17 @@ protected void executeImpl(CommandContext ctxt) throws CommandException { this, Collections.singleton(Permission.DeleteDatasetDraft), doomed); } + // If there is a dedicated thumbnail DataFile, it needs to be reset + // explicitly, or we'll get a constraint violation when deleting: + doomed.setThumbnailFile(null); final Dataset managedDoomed = ctxt.em().merge(doomed); List datasetAndFileSolrIdsToDelete = new ArrayList<>(); // files need to iterate through and remove 'by hand' to avoid - // optimistic lock issues.... + // optimistic lock issues... (plus the physical files need to be + // deleted too!) + Iterator dfIt = doomed.getFiles().iterator(); while (dfIt.hasNext()){ DataFile df = dfIt.next();