package com.cv.hibernate.manytomany.annotation.model;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
* @author Chandra Vardhan
*/
@Entity
@Table(name = "TBL_EMPLOYEE")
public class Employee {
@Id
@Column(name = "EMPLOYEE_ID")
@GeneratedValue
private Long employeeId;
@Column(name = "FIRSTNAME")
private String firstName;;
@Column(name = "LASTNAME")
private String lastName;
@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(name = "EMPLOYEE_MEETING", joinColumns = { @JoinColumn(name = "EMPLOYEE_ID") }, inverseJoinColumns = {
@JoinColumn(name = "MEETING_ID") })
private Set<Meeting> meetings = new HashSet<Meeting>();
public Employee() {
}
public Employee(String firstname, String lastname) {
this.firstName = firstname;
this.lastName = lastname;
}
@Override
public boolean equals(Object emp) {
if (emp instanceof Employee) {
Employee employee = (Employee) emp;
if (this.firstName.equals(employee.getFirstname()) && this.lastName.equals(employee.getLastname()))
return true;
}
return false;
}
@Override
public int hashCode() {
return this.firstName.hashCode() + this.lastName.hashCode();
}
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getFirstname() {
return firstName;
}
public void setFirstName(String firstname) {
this.firstName = firstname;
}
public String getLastname() {
return lastName;
}
public void setLastName(String lastname) {
this.lastName = lastname;
}
public Set<Meeting> getMeetings() {
return meetings;
}
public void setMeetings(Set<Meeting> meetings) {
this.meetings = meetings;
}
} |
No comments:
Post a Comment