while i am trying to add single object to hashSet , it does not accept, but when i give more then one object it will accept
the same code properly work at jvm8, but it does not work at jvm7. some one please help me to resolve this.
package org.student.registration.dao;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.student.jdbc.util.JDBCConnectionUtil;
import org.student.registration.to.StudentContactDetailsTO;
import org.student.registration.to.StudentDetailsTO;
import org.student.registration.to.StudentPreviousEducationDetailsTO;
/**
* @author cerdik
*/
public class AllStudentsDetailsListDAO {
private static final Logger LOGGER = Logger.getLogger(AllStudentsDetailsListDAO.class);
/**
* @accessSpecifier public
* @returnType JSONArray
* @return studentDetails
* @throws ClassNotFoundException
* @throws SQLException
* @throws IOException
* @throws JSONException
*/
public List<StudentDetailsTO> getAllStudentsDelailsList() throws ClassNotFoundException, SQLException, IOException, JSONException{
try{
LOGGER.info("getAllStudentsDelailsList Method started");
int studentId=0;
String retrieveQuery="SELECT "
+ "student_details_t.student_id,"
+ "student_details_t.stream_type_id,"
+ "student_details_t.first_name,"
+ "student_details_t.last_name,"
+ "student_details_t.address,"
+ "student_details_t.gender,"
+ "student_details_t.phone_no,"
+ "student_contact_details_t.student_contact_details_id,"
+ "student_contact_details_t.contact_relation_type_id,"
+ "student_contact_details_t.name,"
+ "student_contact_details_t.address,"
+ "student_contact_details_t.phone_no,"
+ "student_previous_education_details_t.previous_education_details_id,"
+ "student_previous_education_details_t.education_type_id,"
+ "student_previous_education_details_t.institution_of_study,"
+ "student_previous_education_details_t.year_of_passing,"
+ "student_previous_education_details_t.major_paper,"
+ "student_previous_education_details_t.percentage,"
+ "student_previous_education_details_t.board_of_study,"
+ "stream_types_t.stream_type_name,"
+ "education_types_t.education_type_name,"
+ "contact_relation_type_t.contact_relation_type_name "
+ "FROM "
+ "(student_details_t INNER JOIN student_contact_details_t ON student_details_t.student_id=student_contact_details_t.student_id "
+ "INNER JOIN contact_relation_type_t ON student_contact_details_t.contact_relation_type_id=contact_relation_type_t.contact_relation_type_id "
+ "INNER JOIN student_previous_education_details_t ON student_details_t.student_id=student_previous_education_details_t.student_id "
+ "INNER JOIN education_types_t ON education_types_t.education_type_id=student_previous_education_details_t.education_type_id "
+ "INNER JOIN stream_types_t ON stream_types_t.stream_type_id=student_details_t. stream_type_id) "
+ "ORDER BY student_details_t.student_id";
PreparedStatement prepareStatement=JDBCConnectionUtil.getConnection().prepareStatement(retrieveQuery);
ResultSet resultSet=prepareStatement.executeQuery();
LOGGER.info("getAllStudentsDelailsList Query is Excuted");
List<StudentDetailsTO> allStudents=new ArrayList<StudentDetailsTO>();
StudentDetailsTO studentsDetails=null;
HashSet<StudentPreviousEducationDetailsTO>previousEducationDetail=null;//new HashSet<StudentPreviousEducationDetailsTO>();
HashSet<StudentContactDetailsTO>contactDetail=null;//new HashSet<StudentContactDetailsTO>();
while(resultSet.next()){
if(studentsDetails==null){
studentsDetails=new StudentDetailsTO();
studentsDetails.setStudentId(resultSet.getInt("student_id"));
studentsDetails.setStudentStreamId(resultSet.getInt("stream_type_id"));
studentsDetails.setStreamName(resultSet.getString("stream_type_name"));
studentsDetails.setFirstName(resultSet.getString("first_name"));
studentsDetails.setLastName(resultSet.getString("last_name"));
studentsDetails.setAddress(resultSet.getString("address"));
studentsDetails.setGender(resultSet.getString("gender"));
studentsDetails.setPhoneNo(resultSet.getString("phone_no"));
contactDetail=new HashSet<StudentContactDetailsTO>();
StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO();
studentContactDetail.setStudentId(resultSet.getInt("student_id"));
studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_contact_details_id"));
studentContactDetail.setContactTypeName(resultSet.getString("contact_relation_type_name"));
studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_relation_type_id"));
studentContactDetail.setName(resultSet.getString(10));
studentContactDetail.setAddress(resultSet.getString(11));
studentContactDetail.setPhoneNo(resultSet.getString(12));
contactDetail.add(studentContactDetail);
studentsDetails.setStudentContactDetails(contactDetail);
previousEducationDetail=new HashSet<StudentPreviousEducationDetailsTO>();
StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO();
previousEducationDetails.setStudentId(resultSet.getInt("student_id"));
previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id"));
previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("previous_education_details_id"));
previousEducationDetails.setPreviousEducationTypeName(resultSet.getString("education_type_name"));
previousEducationDetails.setInstitutionName(resultSet.getString("institution_of_study"));
previousEducationDetails.setMajorSubject(resultSet.getString("major_paper"));
previousEducationDetails.setPercentage(resultSet.getString("percentage"));
previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_study"));
previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_passing"));
previousEducationDetail.add(previousEducationDetails);
studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail);
}else{
if(resultSet.getInt("student_id")!=studentsDetails.getStudentId()){
allStudents.add(studentsDetails);
studentsDetails=new StudentDetailsTO();
studentsDetails.setStudentId(resultSet.getInt("student_id"));
studentsDetails.setStudentStreamId(resultSet.getInt("stream_type_id"));
studentsDetails.setStreamName(resultSet.getString("stream_type_name"));
studentsDetails.setFirstName(resultSet.getString("first_name"));
studentsDetails.setLastName(resultSet.getString("last_name"));
studentsDetails.setAddress(resultSet.getString("address"));
studentsDetails.setGender(resultSet.getString("gender"));
studentsDetails.setPhoneNo(resultSet.getString("phone_no"));
contactDetail=new HashSet<StudentContactDetailsTO>();
StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO();
studentContactDetail.setStudentId(resultSet.getInt("student_id"));
studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_contact_details_id"));
studentContactDetail.setContactTypeName(resultSet.getString("contact_relation_type_name"));
studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_relation_type_id"));
studentContactDetail.setName(resultSet.getString(10));
studentContactDetail.setAddress(resultSet.getString(11));
studentContactDetail.setPhoneNo(resultSet.getString(12));
contactDetail.add(studentContactDetail);
studentsDetails.setStudentContactDetails(contactDetail);
previousEducationDetail=new HashSet<StudentPreviousEducationDetailsTO>();
StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO();
previousEducationDetails.setStudentId(resultSet.getInt("student_id"));
previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id"));
previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("previous_education_details_id"));
previousEducationDetails.setPreviousEducationTypeName(resultSet.getString("education_type_name"));
previousEducationDetails.setInstitutionName(resultSet.getString("institution_of_study"));
previousEducationDetails.setMajorSubject(resultSet.getString("major_paper"));
previousEducationDetails.setPercentage(resultSet.getString("percentage"));
previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_study"));
previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_passing"));
previousEducationDetail.add(previousEducationDetails);
studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail);
}else{
StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO();
previousEducationDetails.setStudentId(resultSet.getInt("student_id"));
previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id"));
enter code here
previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("p revious_education_details_id"));
previousEducationDetails.setPreviousEducationTypeName(resultSet.getString( "education_type_name"));
previousEducationDetails.setInstitutionName(resultSet.getString("instituti on_of_study"));
previousEducationDetails.setMajorSubject(resultSet.getString("major_paper" ));
previousEducationDetails.setPercentage(resultSet.getString("percentage"));
previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_stu dy"));
previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_pas sing"));
previousEducationDetail.add(previousEducationDetails);
studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail );
}
StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO();
studentContactDetail.setStudentId(resultSet.getInt("student_id"));
studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_ contact_details_id"));
studentContactDetail.setContactTypeName(resultSet.getString("contact_relat ion_type_name"));
studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_re lation_type_id"));
studentContactDetail.setName(resultSet.getString(10));
studentContactDetail.setAddress(resultSet.getString(11));
studentContactDetail.setPhoneNo(resultSet.getString(12));
contactDetail.add(studentContactDetail);
studentsDetails.setStudentContactDetails(contactDetail);
}
}
allStudents.add(studentsDetails);//To add last student object into the list
LOGGER.info("Student Details retrieved by studentId and supply to handler successfully ");
return allStudents;
}catch(ClassNotFoundException e){
LOGGER.error("ERROR OCCURED : ClassNotFoundException getAllStudentsDelailsList Method");
throw e;
}catch(SQLException e){
LOGGER.error("ERROR OCCURED : SQLException getAllStudentsDelailsList Method");
throw e;
}catch(IOException e){
LOGGER.error("ERROR OCCURED : IOException getAllStudentsDelailsList Method");
throw e;
}catch(Exception e){
LOGGER.error("ERROR OCCURED : Exception getAllStudentsDelailsList Method");
throw e;
}
}
}