Fix multiple key exception for sequence->contigFile and
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 18 Aug 2016 10:16:00 +0000 (12:16 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 18 Aug 2016 10:16:00 +0000 (12:16 +0200)
singleRead->pherogram

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/SequenceContigFileCollectionDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/SingleReadPherogramCollectionDetailSection.java

index e959b85f9b9c46acde471218161876bc66e90e9f..7c50960d8c37d7106c6864ba9a0a0e1b6e6ad476 100644 (file)
@@ -13,12 +13,12 @@ import java.util.Collection;
 import java.util.Collections;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import java.util.Collections;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.IMediaService;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 
 /**
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 
 /**
@@ -71,6 +71,14 @@ public class SequenceContigFileCollectionDetailSection extends AbstractEntityCol
     public void addElement(Media element) {
         if(getEntity().getContigFile()==null){
             getEntity().setContigFile(element);
     public void addElement(Media element) {
         if(getEntity().getContigFile()==null){
             getEntity().setContigFile(element);
+                       /*
+                        * merge to avoid duplicate key exception
+                        * the exception seems to be caused by the two links to the Media object: 
+                        *  - Sequence->contigFile (used to be not in the cache after saving)
+                        *  - MediaRepresentationPart->media
+                        *  Invoking merge() solves this problem
+                        */
+            CdmStore.getService(IMediaService.class).merge(element);
         }
     }
 
         }
     }
 
index e78980638e970fb9f457619b2a3e737ea4eb3030..5f887ef261f4aca3955a4223a942ff26b9391926 100644 (file)
@@ -13,8 +13,10 @@ import java.util.Collection;
 import java.util.Collections;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import java.util.Collections;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.IMediaService;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
@@ -69,6 +71,14 @@ public class SingleReadPherogramCollectionDetailSection extends AbstractEntityCo
     public void addElement(Media element) {
         if(getEntity().getPherogram()==null){
             getEntity().setPherogram(element);
     public void addElement(Media element) {
         if(getEntity().getPherogram()==null){
             getEntity().setPherogram(element);
+                       /*
+                        * merge to avoid duplicate key exception
+                        * the exception seems to be caused by the two links to the Media object: 
+                        *  - SingleRead->pherogram (used to be not in the cache after saving)
+                        *  - MediaRepresentationPart->media
+                        *  Invoking merge() solves this problem
+                        */
+            CdmStore.getService(IMediaService.class).merge(element);
         }
     }
 
         }
     }