Merge branch 'hotfix/3.12.4' into develop
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / Sequence.java
index 7bae20f2b77786479dad91eb7c959208a6bb805e..6bc65a7d576c0ff16d071e9af8a44378b882ef95 100644 (file)
@@ -14,13 +14,13 @@ import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToMany;
 import javax.persistence.Transient;
-import javax.validation.constraints.Size;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
@@ -125,19 +125,19 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
 
        /** @see #getGeneticAccessionNumber()*/
        @XmlElement(name = "GeneticAccessionNumber")
-       @Size(max=20)
+    @Column(length=20)
        private String geneticAccessionNumber;
 
        /** @see #getBoldProcessId() */
        @XmlElement(name = "BoldProcessId")
-       @Size(max=20)
+    @Column(length=20)
        private String boldProcessId;
 
     @XmlElementWrapper(name = "SingleReadAlignments")
     @XmlElement(name = "SingleReadAlignment")
     @XmlIDREF
     @XmlSchemaType(name = "IDREF")
-    @OneToMany(mappedBy="consensusAlignment", fetch = FetchType.LAZY)
+    @OneToMany(mappedBy="consensusAlignment", fetch = FetchType.LAZY, orphanRemoval=true)
     @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
        private Set<SingleReadAlignment> singleReadAlignments = new HashSet<SingleReadAlignment>();
 
@@ -152,7 +152,7 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
 
        /** @see #getHaplotype() */
        @XmlElement(name = "Haplotype")
-       @Size(max=100)
+    @Column(length=100)
        private String haplotype;
 
        /** @see #getCitations() */
@@ -427,6 +427,7 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
                this.singleReadAlignments.remove(singleReadAlignment);
                if (this.equals(singleReadAlignment.getConsensusSequence())){
                        singleReadAlignment.setConsensusAlignment(null);
+                       singleReadAlignment.setSingleRead(null);
                }
        }
 //     /**
@@ -437,9 +438,9 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
 //     private void setSingleReadAlignments(Set<SingleReadAlignment> singleReadAlignments) {
 //             this.singleReadAlignments = singleReadAlignments;
 //     }
-       
+
 // *********************** CONVENIENCE ***********************************/
-       
+
        /**
         * Convenience method to add a single read to a consensus sequence
         * by creating a {@link SingleReadAlignment}.
@@ -450,7 +451,7 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
                SingleReadAlignment alignment = SingleReadAlignment.NewInstance(this, singleRead);
                return alignment;
        }
-       
+
        public void removeSingleRead(SingleRead singleRead) {
                Set<SingleReadAlignment> toRemove = new HashSet<SingleReadAlignment>();
                for (SingleReadAlignment align : this.singleReadAlignments){
@@ -463,7 +464,7 @@ public class Sequence extends AnnotatableEntity implements Cloneable{
                }
                return;
        }
-       
+
        /**
         * Convenience method that returns all single reads this consensus sequence
         * is based on via {@link SingleReadAlignment}s.