I am developing an application using Spring and Hibernate with MySQL. I am new to Hibernate and performed basic tasks ...
Now I need to apply joins in select query to retrieve data from multiple tables using annotations. I was looking for him, but still I had no idea ...
Here are my database tables and bean classes:
Table 1: 'employee_info' ( id, empid, empname, doj and jobtitle )
Table 2: 'employee_login' ( username, password, status and empid )
And my bean classes:
EmployeeInfoForm.java
@Entity()
@Table(name = "employee_info")
public class EmployeeInfoForm {
@Id
@GeneratedValue
@Column(name = "id", unique = true, nullable = true)
private int id;
@Column(name = "empId")
private int empId;
@Column(name = "empname")
private String empName;
@Column(name = "doj")
private Date empDoj;
@Column(name = "jobtitle")
private String empJobTitle;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public void setEmpDoj(Date empDoj) {
this.empDoj = empDoj;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Date getEmpDoj() {
return empDoj;
}
public void setEmp_Doj(Date empDoj) {
this.empDoj = empDoj;
}
public String getEmpJobTitle() {
return empJobTitle;
}
public void setEmpJobTitle(String empJobTitle) {
this.empJobTitle = empJobTitle;
}
}
EmployeeLoginForm.java
@Entity()
@Table(name = "employee_login")
public class EmployeeLoginForm {
@Id
@Column(name = "username")
private String empUserName;
@Column(name = "password")
private String empPassword;
@Column(name = "status")
private String empStatus;
@Column(name = "empid")
private int empId;
public String getEmpUserName() {
return empUserName;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public void setEmpUserName(String empUserName) {
this.empUserName = empUserName;
}
public String getEmpPassword() {
return empPassword;
}
public void setEmpPassword(String empPassword) {
this.empPassword = empPassword;
}
public String getEmpStatus() {
return empStatus;
}
public void setEmpStatus(String empStatus) {
this.empStatus = empStatus;
}
}
Requirements:
I want to select the empid, empname, jobtitle fields from employee_info and the status field from employee_login table when there are empirical matches on both tables ...
Please help me complete my work ...
Any suggestions and recommendations appreciated ...