日期:2014-05-19  浏览次数:20751 次

Hibernate 双向一对多的关联问题,在线等啊
我现在有两张表,一个employee,一张evaluate,其中employee的emp_id是evaluate的外键,代码及配置文件如下:employee.java


package com.yinhai.giuzhou.employee.demo;

import com.yinhai.giuzhou.evaluate.demo.Evaluate;

public class Employee {
private int emp_id;
private String emp_name;
private String emp_sex;
private String emp_birth;
private String emp_job;
private String emp_office_tel;
private String emp_note;
private String emp_pic;
private int emp_login;
private String emp_pwd;
private String login_name;
private Evaluate evaluate;


public void setEvaluate(Evaluate evaluate) {
this.evaluate = evaluate;
}

public Evaluate getEvaluate() {
return evaluate;
}

public int getEmp_id() {
return emp_id;
}

public void setEmp_id(int empId) {
emp_id = empId;
}

public String getEmp_name() {
return emp_name;
}

public void setEmp_name(String empName) {
emp_name = empName;
}

public String getEmp_sex() {
return emp_sex;
}

public void setEmp_sex(String empSex) {
emp_sex = empSex;
}

public String getEmp_birth() {
return emp_birth;
}

public void setEmp_birth(String empBirth) {
emp_birth = empBirth;
}

public String getEmp_job() {
return emp_job;
}

public void setEmp_job(String empJob) {
emp_job = empJob;
}

public String getEmp_office_tel() {
return emp_office_tel;
}

public void setEmp_office_tel(String empOfficeTel) {
emp_office_tel = empOfficeTel;
}

public String getEmp_note() {
return emp_note;
}

public void setEmp_note(String empNote) {
emp_note = empNote;
}

public String getEmp_pic() {
return emp_pic;
}

public void setEmp_pic(String empPic) {
emp_pic = empPic;
}

public int getEmp_login() {
return emp_login;
}

public void setEmp_login(int empLogin) {
emp_login = empLogin;
}

public String getEmp_pwd() {
return emp_pwd;
}

public void setEmp_pwd(String empPwd) {
emp_pwd = empPwd;
}

public String getLogin_name() {
return login_name;
}

public void setLogin_name(String loginName) {
login_name = loginName;
}


}

evaluate.java:

package com.yinhai.giuzhou.evaluate.demo;

import java.util.Date;

import com.yinhai.giuzhou.employee.demo.Employee;

public class Evaluate {

private int evaluate_id;
private Date evaluate_time;
private String evaluate_result;
private Employee employee;


public Employee getEmployee() {
return employee;
}

public void setEmployee(Employee employee) {
this.employee = employee;
}

public int getEvaluate_id() {
return evaluate_id;
}

public void setEvaluate_id(int evaluateId) {
evaluate_id = evaluateId;
}

public Date getEvaluate_time() {
return evaluate_time;
}

public void setEvaluate_time(Date evaluateTime) {
evaluate_time = evaluateTime;
}

public String getEvaluate_result() {
return evaluate_result;
}

public void setEvaluate_result(String evaluateResult) {
evaluate_result = evaluateResult;
}

}


Employee.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mappi