I am trying to relate two tables with spring / hibernate in MYSQL like this
@Table (name = candidatresumeinfo)
public class CandidateResumeInfo implements Serializable
{
List<SelectedResumes> selectedResumes;
.............
..............
@JoinColumn(name = "selectedresumeid")
@OneToMany
public List<SelectedResumes> getSelectedResumes() {
return selectedResumes;
}
public void setSelectedResumes(List<SelectedResumes> selectedResumes) {
this.selectedResumes = selectedResumes;
}
Now ,i got the data in my list correctly( i checked in debug)but the call from server is getting failed which is saying cause:Nullpointer exception .
thanks
You can use
OneToManyannotation only on Collections, so you should change the field to Set or List, because hibernate will return multiple result if you use OneToMany. I think you’d like to use ManyToOne annotation here.ManyToOnemeans here that you have multiple CandidateResumeInfo for one SelectedResumes.OneToManymeans here that you have multiple SelectedResumes for one CandidateResumeInfo.This annotation naming can be a bit strange for first time. Hope I helped.
Answer for your comment:
The best way is you declare the relationship both side.
Here is the example:
CandidateResumeInfo.java:
SelectedResumes.java: