Following is the table structure:
desc customer_survey
Name Null Type
----------- -------- ------------
SURVEYID NOT NULL VARCHAR2(10)
CUSTNO NOT NULL VARCHAR2(10)
SRNO NUMBER(10)
AVGRATINGS NUMBER(5,2)
COMMENTS VARCHAR2(50)
SENTON DATE
RESPONDEDON DATE
desc Survey_response
Name Null Type
---------------- -------- ------------
SURVEYRESPONSEID NOT NULL NUMBER(10)
RATINGS NOT NULL NUMBER(2)
QNO NOT NULL VARCHAR2(10)
SURVEYID NOT NULL VARCHAR2(10)
Java classes:
public class CustomerSurvey implements Serializable {
@OneToMany(fetch=FetchType.EAGER, mappedBy="customerSurvey",
cascade=CascadeType.ALL)
private Set<SurveyResponse> responses;
......
public class SurveyResponse {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="SURVEYID", referencedColumnName="surveyId")
private CustomerSurvey customerSurvey;
......
Client code:
List<CustomerSurvey> surveys = workService.getSurveysByCustomer("testCNo2");
System.out.println("surveys size = " + surveys.size());
for(CustomerSurvey survey: surveys) {
System.out.println("getting responses from the survey object now..");
Set<SurveyResponse> responses = survey.getResponses();
System.out.println("responses size= .." + responses.size());
}
console shows:
surveys size = 1 getting responses from the survey object now.. responses size= ..0
whereas there are 7 responses in the DB for the selected survey.