package entity.company2; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.UniqueConstraint; /** * * {@link Employee} instances related to {@link Department} * */ @Entity @Table(uniqueConstraints={@UniqueConstraint(columnNames={"staffNumber"})}) public class Employee { @Id @GeneratedValue public Long getId() {return id;} protected void setId(Long id) {this.id = id;} private Long id; public int getStaffNumber() { return staffNumber;} public void setStaffNumber(int staffNumber) { this.staffNumber = staffNumber;} int staffNumber = Integer.MIN_VALUE; public String getCname() { return cname;} public void setCname(String cname) { this.cname = cname;} private String cname; // Common name /** * @return Laptop possibly "owned" by {@link Employee}. */ @OneToOne(cascade={CascadeType.ALL}) public Laptop getLaptop() { return laptop;} public void setLaptop(Laptop laptop) {this.laptop = laptop;} private Laptop laptop;// Workstation for employees. protected Employee(){} public Employee(final int staffNumber, final String cname) { setStaffNumber(staffNumber); setCname(cname); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (Integer.MIN_VALUE == getStaffNumber()) { return false; } else if (other instanceof Employee) { final Employee that = (Employee) other; return this.getStaffNumber() == that.getStaffNumber(); } else { return false; } } @Override public int hashCode() { if (Integer.MIN_VALUE == getStaffNumber()) { return System.identityHashCode(this); } else { return getStaffNumber(); } } }