Changed DefinedTermBase.media form OneToMany to ManyToMany #560
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / DefinedTermBase.java
index 19072cafb455da4d809c55a6d8a93a3554e52c94..f17b90d3fd6a27a752002dd7f4c2518be101fd17 100644 (file)
@@ -19,9 +19,11 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
+import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToMany;
 import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -141,7 +143,8 @@ public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBas
        @XmlElement(name = "Medium")
     @XmlIDREF
     @XmlSchemaType(name = "IDREF")
-    @OneToMany(fetch = FetchType.LAZY)
+    @ManyToMany(fetch = FetchType.LAZY)
+       @OneToMany(fetch = FetchType.LAZY)
        @Cascade({CascadeType.SAVE_UPDATE})
        private Set<Media> media = new HashSet<Media>();
        
@@ -152,6 +155,8 @@ public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBas
        @Cascade(CascadeType.SAVE_UPDATE)
        protected TermVocabulary<T> vocabulary; 
        
+//***************************** CONSTRUCTOR *******************************************/       
+       
        public DefinedTermBase() {
                super();
        }
@@ -159,15 +164,20 @@ public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBas
                super(term, label, labelAbbrev);
        }
 
-       protected abstract void setDefaultTerms(TermVocabulary<T> termVocabulary);
+//******************************* METHODS ******************************************************/
+       
+       public abstract void resetTerms();
 
+       protected abstract void setDefaultTerms(TermVocabulary<T> termVocabulary);
+       
+       
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.util.List)
         */
        public T readCsvLine(Class<T> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms) {
                try {
                        T newInstance = termClass.newInstance();
-                   return readCsvLine(newInstance, csvLine, Language.ENGLISH());
+                   return readCsvLine(newInstance, csvLine, Language.CSV_LANGUAGE());
                } catch (Exception e) {
                        logger.error(e);
                        for(StackTraceElement ste : e.getStackTrace()) {
@@ -307,16 +317,18 @@ public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBas
                this.media.remove(media);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getVocabulary()
+       /**
+        * @return
         */
        public TermVocabulary<T> getVocabulary() {
                return this.vocabulary;
        }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#setVocabulary(eu.etaxonomy.cdm.model.common.TermVocabulary)
+
+       //for bedirectional use only, use vocabulary.addTerm instead
+       /**
+        * @param newVocabulary
         */
-       public void setVocabulary(TermVocabulary<T> newVocabulary) {
+       protected void setVocabulary(TermVocabulary<T> newVocabulary) {
                this.vocabulary = newVocabulary;                
        }       
 }
\ No newline at end of file