Hello
Thanks for the reply.I am pasting the annotated classes and an image of the schema design.I have implemented a join for two of the tables,but no idea how it can be done for more tables.Also,my database is a existing one,and i don't want to use an extra association table(that is created during association) or foreign key column created newly.Instead I want to use the existing primary/foreign key mapping.
These are the tables:
Candidates.javaCode:
package com.hibernate.candidate;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.CascadeType;
@Entity
@Table(name="HC_RESUME_BANK")
public class Candidates{
private int id;
private String firstName;
private String lastName;
private String email;
private Set<CandidateStatus> candidateStats = new HashSet<CandidateStatus>(0);
@OneToMany(mappedBy="candidate")
@JoinColumn(name="ResID",nullable=false)
public Set<CandidateStatus> getCandidateStats() {
return candidateStats;
}
public void setCandidateStats(Set<CandidateStatus> candidateStats) {
this.candidateStats = candidateStats;
}
@Id
@Column(name="RID")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="FirstName")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name="LastName")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name="EmailID")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
CandidateStatus.javaCode:
package com.hibernate.candidate;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.CascadeType;
@Entity
@Table(name="HC_RESUME_BANK")
public class Candidates{
private int id;
private String firstName;
private String lastName;
private String email;
private Set<CandidateStatus> candidateStats = new HashSet<CandidateStatus>(0);
@OneToMany(mappedBy="candidate")
@JoinColumn(name="ResID",nullable=false)
public Set<CandidateStatus> getCandidateStats() {
return candidateStats;
}
public void setCandidateStats(Set<CandidateStatus> candidateStats) {
this.candidateStats = candidateStats;
}
@Id
@Column(name="RID")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="FirstName")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name="LastName")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name="EmailID")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Requirements.javaCode:
package com.hibernate.candidate;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="HC_REQUISISTIONS")
public class Requirements {
private int id;
private String requirement;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRequirement() {
return requirement;
}
public void setRequirement(String requirement) {
this.requirement = requirement;
}
}
[img]file:///E:/db_schema.jpg[/img]
Hope I am clear enough,if not please let me know.
Thanks
Sachin