Joined: Wed Nov 12, 2008 4:18 am Posts: 2 Location: Singapore
|
if it is possible then i understand the ID columns can be any single column or composite columns.
I have a problem when trying to establish a relationship between a view and a table.
I am pasting the code,
1 . Lecture View
@Entity
@Table(name="NCE_EPF_LPA")
public class LecturerPartics {
private String deptCode;
private String staffNo;
private String facultyCode;
private Department department;
@Id
@Column(name="STF_N")
public String getStaffNo() {
return staffNo;
}
public void setStaffNo(String staffNo) {
this.staffNo = staffNo;
}
@Column(name="DEPT_C")
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}
@Column(name="FAC_C")
public String getFacultyCode() {
return facultyCode;
}
public void setFacultyCode(String facultyCode) {
this.facultyCode = facultyCode;
}
@ManyToOne
@JoinColumn(name="DEPT_C")
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
2. Department Table
@Entity
@Table(name="DEPARTMENT")
public class Department {
private String deptCode;
private String facCode;
private Faculty faculty;
private List<LecturerPartics> lecturer = new ArrayList<LecturerPartics>();
@Id
@Column(name="DEPT_C")
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}
@Column(name="FAC_C")
public String getFacCode() {
return facCode;
}
public void setFacCode(String facCode) {
this.facCode = facCode;
}
@OneToMany(mappedBy="department")
@PrimaryKeyJoinColumn
public List<LecturerPartics> getLecturer() {
return lecturer;
}
public void setLecturer(List<LecturerPartics> lecturer) {
this.lecturer = lecturer;
}
// equals and hashcode included
@OneToMany(mappedBy="department")
@JoinColumn(name="FAC_C")
public Faculty getFaculty() {
return faculty;
}
public void setFaculty(Faculty faculty) {
this.faculty = faculty;
}
}
3. Faculty <Table> -- please note it doesn't have any column to map to department.
@Entity
@Table(name="FACULTY")
public class Faculty {
private String facultyCode;
private String facultyText;
private Department department;
@Id
@Column(name="FAC_C")
public String getFacultyCode() {
return facultyCode;
}
public void setFacultyCode(String facultyCode) {
this.facultyCode = facultyCode;
}
@Column(name="FAC_T")
public String getFacultyText() {
return facultyText;
}
public void setFacultyText(String facultyText) {
this.facultyText = facultyText;
}
@OneToMany(mappedBy="faculty",fetch=FetchType.LAZY)
@JoinColumn(name="FAC_C")
public List<LecturerPartics> getLecturer() {
return lecturer;
}
public void setLecturer(List<LecturerPartics> lecturer) {
this.lecturer = lecturer;
}
@ManyToOne
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
// equals and hashcode implemented
}
Please let me know if i am doing something wrong here.
-Murali*
|
|