Fixing hibernate mappings relating to issues #457 and #460, allowing schema generatio...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / RelationshipBase.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.model.common;
11
12 import javax.persistence.MappedSuperclass;
13 import javax.persistence.Transient;
14 import javax.persistence.FetchType;
15 import javax.persistence.ManyToOne;
16 import javax.persistence.MappedSuperclass;
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlType;
21
22 import org.apache.log4j.Logger;
23
24 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
25
26 import org.apache.log4j.Logger;
27 import org.hibernate.annotations.Cascade;
28 import org.hibernate.annotations.CascadeType;
29
30 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
31 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
32
33 /**
34 * @author m.doering
35 */
36 @XmlAccessorType(XmlAccessType.FIELD)
37 @XmlType(name = "RelationshipBase", propOrder = { })
38 @XmlRootElement(name = "RelationshipBase")
39 @MappedSuperclass
40 public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase> extends ReferencedEntityBase {
41 private static final long serialVersionUID = -5030154633820061997L;
42 static Logger logger = Logger.getLogger(RelationshipBase.class);
43
44 protected RelationshipBase(){
45 super();
46 }
47
48 /**
49 * Creates a relationship between 2 objects and adds it to the respective
50 * relation sets of both objects.
51 *
52 * @param from
53 * @param to
54 * @param type
55 * @param citation
56 * @param citationMicroReference
57 */
58 protected RelationshipBase(FROM from, TO to, TYPE type, ReferenceBase citation, String citationMicroReference) {
59 super(citation, citationMicroReference, null);
60 setRelatedFrom(from);
61 setRelatedTo(to);
62 setType(type);
63 from.addRelationship(this);
64 to.addRelationship(this);
65 }
66
67 @Transient
68 public abstract TYPE getType();
69
70 protected abstract void setType(TYPE type);
71
72 @Transient
73 protected abstract FROM getRelatedFrom();
74
75 protected abstract void setRelatedFrom(FROM relatedFrom);
76
77 @Transient
78 protected abstract TO getRelatedTo();
79
80 protected abstract void setRelatedTo(TO relatedTo);
81
82 // TODO
83 // UUID toUuid;
84 // UUID fromUuid;
85 //
86 // @Transient
87 // public UUID getToUuidCache(){
88 // return relationTo.getUuid();
89 // }
90 // protected void setToUuid(UUID uuid){
91 // toUuid = uuid;
92 // }
93 //
94 // public UUID getFromUuid(){
95 // return relationTo.getUuid();
96 // }
97 // protected void setFromUuid(UUID uuid){
98 // fromUuid = uuid;
99 // }
100 }