我正在使用 Spring 和 Hibernate 和 MySQL 开发应用程序。我是 Hibernate 的新手,做了一些基本的任务......
现在我需要在选择查询中应用连接以使用注释从多个表中获取数据。我已经搜索过了,但我仍然没有任何想法......
这是我的数据库表和 bean 类:
Table 1: 'employee_info' ( id, empid, empname, doj and jobtitle )
Table 2: 'employee_login' ( username, password, status and empid )
我的豆类是:
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;
}
}
要求:
当empid在两个表上都匹配时,我想从employee_info和employee_login表中选择字段empid ,empname ,jobtitle和字段状态...
请帮我完成我的工作...
任何建议和指导表示赞赏...