We just switched to Glassfish V2. We are now getting errors when setting a session attribute.
Error is:
java.lang.IllegalArgumentException: PWC2788: setAttribute: Non-serializable attribute
Code is:
getRequest().getSession().setAttribute("questionsForUser", getQuestions());
getQuestions() is just a simple getter which is inside an abstract class named 'Parent Action'....so to make getQuestions() a serialized object does my class need to implement serializable?:
public List getQuestions() {
return questions;
}
- How can we make this object serializable?
- is it a good practice to only put serialized object in the session (as Glassfish appears to be requiring)?
- Are there risks of sessions being swapped between users with serialized objects?
Edit: I am using ORM (iBatis)
More Information about "Questions"
setter:
public void setQuestions(List questions) {
this.questions = questions;
}
setter is called inside this method. this method calls the iBatis mappings.
public void prepareQuestions()
{
setExamIfaceDAO((SecurityExamIfaceDAO)ApplicationInitializer.getApplicationContext().getBean("securityExamIfaceDAO"));
String userRole = questionsBasedOnUserRole();
int questionsToBeShown = 0;
if (userRole.equalsIgnoreCase("C"))
questionsToBeShown = 15;
else if (userRole.equalsIgnoreCase("U"))
questionsToBeShown = 10;
List local_questions = getExamIfaceDAO().getSecurityQuestions(userRole);
Collections.shuffle(local_questions);
if (local_questions.size()>=questionsToBeShown)
setQuestions(local_questions.subList(0, questionsToBeShown));
getRequest().getSession().setAttribute("questionsForUser", getQuestions());
}