我有两个主键为 emp_id 的表。我正在使用 Spring、Hibernate、MVC。
域文件:
public class Employee_Domain {
private static final long serialVersionUID = 1L;
private Integer emp_id;
private String domain_name;
@OneToOne @PrimaryKeyJoinColumn
private Employee empDomObj;
@Id
@Column(name = "EMP_ID", unique = true, nullable = false)
public Integer getEmp_id() {
return emp_id;
}
public void setEmp_id(Integer emp_id) {
this.emp_id = emp_id;
}
@Column(name = "DOMAIN_NAME", unique = false, nullable = true, length = 200)
public String getDomain_name() {
return domain_name;
}
public void setDomain_name(String domain_name) {
this.domain_name = domain_name;
}
}
和
public class Employee implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer emp_id;
private String emp_name;
private String emp_role;
@OneToOne @PrimaryKeyJoinColumn
private Employee_Domain empDomObj;
@Id
@Column(name = "EMP_ID", unique = true, nullable = false)
public Integer getEmp_id() {
return emp_id;
}
public void setEmp_id(Integer emp_id) {
this.emp_id = emp_id;
}
@Column(name = "EMP_NAME", unique = false, nullable = false, length = 500)
public String getEmp_name() {
return emp_name;
}
public void setEmp_name(String emp_name) {
this.emp_name = emp_name;
}
@Column(name = "ROLE", unique = false, nullable = false, length = 100)
public String getEmp_role() {
return emp_role;
}
public void setEmp_role(String emp_role) {
this.emp_role = emp_role;
}
我的 domainDao 实现是这样的:
@Override
public List<Employee_Domain> findEmployeeByDomain1(String domain_name) {
Criteria criteria = getSession().createCriteria(Employee_Domain.class);
criteria.setFetchMode("EMP_DETAILS", FetchMode.JOIN);
criteria.add(Restrictions.eq("domain_name", domain_name));
return criteria.list();
}
并使用 MVC 即时调用此函数并将对象传递给 jsp 以打印它。
执行这个会带来一个简单的 SQL 查询:
select this_.EMP_ID as EMP1_3_0_, this_.DOMAIN_NAME as DOMAIN2_3_0_ from EMPLOYEE_DOMAIN_MAPPING this_ where this_.DOMAIN_NAME=?
为什么没有连接发生?我错过了什么?我对这一切都是新手,所以请不要锤我。我尝试了很多类似的例子,但没有得到。