1

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;
        }
    }
 }
Vasantha Raj
  • 637
  • 1
  • 6
  • 22
  • 4
    Welcome! Please read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Your code is too long. – Tagir Valeev May 06 '15 at 05:52
  • And please [don't log-and-throw](http://stackoverflow.com/questions/6639963/why-is-log-and-throw-condsidered-an-anti-pattern). – aroth May 06 '15 at 05:54
  • I recommend you spend some time breaking this code down into a few more methods. It will be a lot more comprehensible and will make it easier to debug. Any time you're declaring 4 unrelated exceptions can be thrown from a single method, that's a red flag. – Steve Chaloner May 06 '15 at 06:00

1 Answers1

0

Put jackson-all-1.9.0.jar you might have miss that dependency.After that code might have work perfectly.

Murugesan Era
  • 335
  • 1
  • 17
  • I'm baffled as to how you could determine that was the issue based upon the question provided. – aroth May 06 '15 at 06:25
  • I had experienced that issue ,while i am doing project.it's my guess the person may have same problem that's it. – Murugesan Era May 06 '15 at 07:15
  • I'm with @aroth . Can you explain your answer please. Are you saying this is the difference between jvm 7 and 8 or are you saying that only a portion of the problem is being displayed here ? An answer based on creating hashcode and equals method for the objects being added to the hashset or on similar lines would have been less surprising. There isn't even a stacktrace in question.. so how? – Gyan May 06 '15 at 11:02