Created
November 19, 2017 19:28
-
-
Save Lodo4ka/40e6742aeeef4fbd61ff220e4285a005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.testbackfortheinterview.interview.entity; | |
import com.testbackfortheinterview.interview.entity.enums.TypeDepartment; | |
import javax.persistence.*; | |
import java.util.List; | |
@Entity | |
@Table(name = "DEPARTMENT") | |
public class Department { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "ID") | |
private long id; | |
@Column(unique = true, nullable = false) | |
private String name; | |
private TypeDepartment department; | |
// здесь неправильный именование для сущности | |
@OneToMany(mappedBy = "furnitures") | |
private List<Furniture> furnitureList; | |
@OneToMany(mappedBy = "orders") | |
private List<Order> orderList; | |
@OneToMany(mappedBy = "masters") | |
private List<Master> masterList; | |
public Department() { | |
} | |
public Department(final TypeDepartment department) { | |
this.department = department; | |
} | |
public Department(final long id, final String name, final TypeDepartment department, final List<Furniture> furnitureList, final List<Order> orderList, final List<Master> masterListp) { | |
this.id = id; | |
this.name = name; | |
this.department = department; | |
this.furnitureList = furnitureList; | |
this.orderList = orderList; | |
this.masterList = masterListp; | |
} | |
public long getId() { | |
return id; | |
} | |
public void setId(final long id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(final String name) { | |
this.name = name; | |
} | |
public TypeDepartment getDepartment() { | |
return department; | |
} | |
public void setDepartment(TypeDepartment department) { | |
this.department = department; | |
} | |
public List<Furniture> getFurnitureList() { | |
return furnitureList; | |
} | |
public void setFurnitureList(final List<Furniture> furnitureList) { | |
this.furnitureList = furnitureList; | |
} | |
public List<Order> getOrderList() { | |
return orderList; | |
} | |
public void setOrderList(final List<Order> orderList) { | |
this.orderList = orderList; | |
} | |
public List<Master> getMasterList() { | |
return masterList; | |
} | |
public void setMasterList(final List<Master> masterList) { | |
this.masterList = masterList; | |
} | |
@Override | |
public boolean equals(final Object o) { | |
if (this == o) return true; | |
if (!(o instanceof Department)) return false; | |
Department that = (Department) o; | |
if (getId() != that.getId()) return false; | |
if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false; | |
if (getDepartment() != that.getDepartment()) return false; | |
if (getFurnitureList() != null ? !getFurnitureList().equals(that.getFurnitureList()) : that.getFurnitureList() != null) | |
return false; | |
if (getOrderList() != null ? !getOrderList().equals(that.getOrderList()) : that.getOrderList() != null) | |
return false; | |
return getMasterList() != null ? getMasterList().equals(that.getMasterList()) : that.getMasterList() == null; | |
} | |
@Override | |
public int hashCode() { | |
int result = (int) (getId() ^ (getId() >>> 32)); | |
result = 31 * result + (getName() != null ? getName().hashCode() : 0); | |
result = 31 * result + (getDepartment() != null ? getDepartment().hashCode() : 0); | |
result = 31 * result + (getFurnitureList() != null ? getFurnitureList().hashCode() : 0); | |
result = 31 * result + (getOrderList() != null ? getOrderList().hashCode() : 0); | |
result = 31 * result + (getMasterList() != null ? getMasterList().hashCode() : 0); | |
return result; | |
} | |
@Override | |
public String toString() { | |
return "Department{" + | |
"id=" + id + | |
", name='" + name + '\'' + | |
", department=" + department + | |
", furnitureList=" + furnitureList + | |
", orderList=" + orderList + | |
", masterList=" + masterList + | |
'}'; | |
} | |
} | |
package com.testbackfortheinterview.interview.entity; | |
import com.testbackfortheinterview.interview.entity.enums.TypeDepartment; | |
import com.testbackfortheinterview.interview.entity.enums.TypeofFurniture; | |
import javax.persistence.*; | |
@Entity | |
@Table(name = "FURNITURE") | |
public class Furniture { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "ID") | |
private long id; | |
@Column(unique = true, nullable = false) | |
private String name; | |
@ManyToOne | |
@JoinColumn(name = "DEPARTMENT_ID", nullable = false) | |
private Department department; | |
private TypeofFurniture typeofFurniture; | |
public Furniture() { | |
} | |
public Furniture(final String name, final Department department, final TypeofFurniture typeofFurniture) { | |
this.name = name; | |
this.department = department; | |
this.typeofFurniture = typeofFurniture; | |
} | |
public long getId() { | |
return id; | |
} | |
public void setId(final long id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(final String name) { | |
this.name = name; | |
} | |
public Department getDepartment() { | |
return department; | |
} | |
public void setDepartment(final Department department) { | |
this.department = department; | |
} | |
public TypeofFurniture getTypeofFurniture() { | |
return typeofFurniture; | |
} | |
public void setTypeofFurniture(final TypeofFurniture typeofFurniture) { | |
this.typeofFurniture = typeofFurniture; | |
} | |
@Override | |
public boolean equals(final Object o) { | |
if (this == o) return true; | |
if (!(o instanceof Furniture)) return false; | |
Furniture furniture = (Furniture) o; | |
if (getId() != furniture.getId()) return false; | |
if (getName() != null ? !getName().equals(furniture.getName()) : furniture.getName() != null) return false; | |
if (getDepartment() != null ? !getDepartment().equals(furniture.getDepartment()) : furniture.getDepartment() != null) | |
return false; | |
return getTypeofFurniture() == furniture.getTypeofFurniture(); | |
} | |
@Override | |
public int hashCode() { | |
int result = (int) (getId() ^ (getId() >>> 32)); | |
result = 31 * result + (getName() != null ? getName().hashCode() : 0); | |
result = 31 * result + (getDepartment() != null ? getDepartment().hashCode() : 0); | |
result = 31 * result + (getTypeofFurniture() != null ? getTypeofFurniture().hashCode() : 0); | |
return result; | |
} | |
@Override | |
public String toString() { | |
return "Furniture{" + | |
"id=" + id + | |
", name='" + name + '\'' + | |
", department=" + department + | |
", typeofFurniture=" + typeofFurniture + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment