【发布时间】:2015-02-05 18:40:32
【问题描述】:
鉴于这个image,我想知道我是否应该在其他文件中使用mappedBy 的同时使用JoinColumn。或者,如果我不需要使用mappedBy,那就可以了!
谁能告诉我为什么我们需要使用mappedBy?
Employee.java
@Id
@GeneratedValue
@Column(name="employee_id")
private Long employeeId;
@Column(name="firstname")
private String firstname;
@Column(name="lastname")
private String lastname;
@Column(name="birth_date")
private Date birthDate;
@Column(name="cell_phone")
private String cellphone;
@ManyToOne
@JoinColumn(name="department_id")
private Department department;
public Employee() {
}
public Employee(String firstname, String lastname, String phone) {
this.firstname = firstname;
this.lastname = lastname;
this.birthDate = new Date(System.currentTimeMillis());
this.cellphone = phone;
}
// Getter and Setter methods
Department.java
@Id
@GeneratedValue
@Column(name="DEPARTMENT_ID")
private Long departmentId;
@Column(name="DEPT_NAME")
private String departmentName;
@OneToMany(mappedBy="department")
private Set<employee> employees;
// Getter and Setter methods
【问题讨论】:
标签: java hibernate spring-mvc jpa