diff --git a/doc/release-notes/11990-controlled-vocab-edit-error.md b/doc/release-notes/11990-controlled-vocab-edit-error.md new file mode 100644 index 00000000000..8e98d10b40a --- /dev/null +++ b/doc/release-notes/11990-controlled-vocab-edit-error.md @@ -0,0 +1,5 @@ +### Bug Fix + +Editing a controlled vocabulary field (i.e. one with values specified in the field's metadatablock) that only allows a single selection would also update the value in the prior published version if (and only if) the edit was made starting from the published version (versus an existing draft). This is now fixed. +The bug appears to be 11+ years old and previously unreported. As the value in the database was overwritten, there is no simple way to detect if/when this occurred without looking at backups or archival file copies. + diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetField.java b/src/main/java/edu/harvard/iq/dataverse/DatasetField.java index a735ae7470c..dc19f73cd81 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetField.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetField.java @@ -172,7 +172,6 @@ public void setParentDatasetFieldCompoundValue(DatasetFieldCompoundValue parentD } @OneToMany(mappedBy = "parentDatasetField", orphanRemoval = true, cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}) - @OrderBy("displayOrder ASC") private List datasetFieldCompoundValues = new ArrayList<>(); public List getDatasetFieldCompoundValues() { @@ -197,6 +196,7 @@ public void setDatasetFieldValues(List datasetFieldValues) { @ManyToMany(cascade = {CascadeType.MERGE}) @JoinTable(indexes = {@Index(columnList="datasetfield_id"),@Index(columnList="controlledvocabularyvalues_id")}) + @OrderBy("displayOrder ASC") private List controlledVocabularyValues = new ArrayList<>(); public List getControlledVocabularyValues() { @@ -604,14 +604,15 @@ private DatasetField copy(Object versionOrTemplate, DatasetFieldCompoundValue pa if (versionOrTemplate != null) { if (versionOrTemplate instanceof DatasetVersion) { - dsf.setDatasetVersion((DatasetVersion) versionOrTemplate); + dsf.setDatasetVersion((DatasetVersion) versionOrTemplate); } else { dsf.setTemplate((Template) versionOrTemplate); } } dsf.setParentDatasetFieldCompoundValue(parent); - dsf.setControlledVocabularyValues(controlledVocabularyValues); + + dsf.getControlledVocabularyValues().addAll(controlledVocabularyValues); for (DatasetFieldValue dsfv : datasetFieldValues) { dsf.getDatasetFieldValues().add(dsfv.copy(dsf));