]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
A @OneToMany annotation always causes that in the target entity's table the column...
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / department / CompanyDepartment.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.department;
18
19 import java.util.Objects;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.FetchType;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import org.mxchange.jcontactsbusiness.BusinessContact;
33 import org.mxchange.jcontactsbusiness.CompanyContact;
34 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
35 import org.mxchange.jcontactsbusiness.employee.Employee;
36
37 /**
38  * A POJO for company departments
39  * <p>
40  * @author Roland Haeder
41  */
42 @Entity (name = "company_departments")
43 @Table (name = "company_departments")
44 public class CompanyDepartment implements Department, Comparable<Department> {
45
46         /**
47          * Serial number
48          */
49         private static final long serialVersionUID = 94_835_918_958_717_660L;
50
51         /**
52          * Connection to company contact
53          */
54         @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
55         @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
56         private BusinessContact departmentCompany;
57
58         /**
59          * Id number
60          */
61         @Id
62         @GeneratedValue (strategy = GenerationType.IDENTITY)
63         @Column (name = "department_id", length = 20, nullable = false, updatable = false)
64         private Long departmentId;
65
66         /**
67          * Department lead employee
68          */
69         @JoinColumn (name = "department_lead_id", nullable = false)
70         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
71         private Employee departmentLead;
72
73         /**
74          * Department name
75          */
76         @Basic (optional = false)
77         @Column (name = "department_name", length = 100, nullable = false)
78         private String departmentName;
79
80         @Override
81         public int compareTo (final Department department) {
82                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83         }
84
85         @Override
86         public boolean equals (final Object object) {
87                 if (object == null) {
88                         return false;
89                 } else if (getClass() != object.getClass()) {
90                         return false;
91                 }
92
93                 final Department other = (Department) object;
94
95                 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
96                         return false;
97                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
98                         return false;
99                 }
100
101                 return true;
102         }
103
104         @Override
105         public BusinessContact getDepartmentCompany () {
106                 return this.departmentCompany;
107         }
108
109         @Override
110         public void setDepartmentCompany (final BusinessContact departmentCompany) {
111                 this.departmentCompany = departmentCompany;
112         }
113
114         @Override
115         public Long getDepartmentId () {
116                 return this.departmentId;
117         }
118
119         @Override
120         public void setDepartmentId (final Long departmentId) {
121                 this.departmentId = departmentId;
122         }
123
124         @Override
125         public Employee getDepartmentLead () {
126                 return this.departmentLead;
127         }
128
129         @Override
130         public void setDepartmentLead (final Employee departmentLead) {
131                 this.departmentLead = departmentLead;
132         }
133
134         @Override
135         public String getDepartmentName () {
136                 return this.departmentName;
137         }
138
139         @Override
140         public void setDepartmentName (final String departmentName) {
141                 this.departmentName = departmentName;
142         }
143
144         @Override
145         public int hashCode () {
146                 int hash = 5;
147                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
148                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
149                 return hash;
150         }
151 }