title: setAttribute: Non-serializable attribute (Java Object Serialization)
body: <p>We just switched to Glassfish V2.  We are now getting errors when setting a session attribute.</p>
  
  <p>Error is:</p>
  
  <pre><code>java.lang.IllegalArgumentException: PWC2788: setAttribute: Non-serializable attribute
  </code></pre>
  
  <p>Code is:</p>
  
  <pre><code>getRequest().getSession().setAttribute("questionsForUser", getQuestions());
  </code></pre>
  
  <p>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?:</p>
  
  <pre><code>public List getQuestions() {
      return questions;
  }
  </code></pre>
  
  <ul>
  <li>How can we make this object
  serializable?</li>
  <li>is it a good practice to only put
  serialized object in the session (as
  Glassfish appears to be requiring)?</li>
  <li>Are there risks of sessions being
  swapped between users with serialized
  objects?</li>
  </ul>
  
  <p>Edit: I am using ORM (iBatis)</p>
  
  <p>More Information about "Questions"</p>
  
  <p>setter:</p>
  
  <pre><code>public void setQuestions(List questions) {
      this.questions = questions;
  }
  </code></pre>
  
  <p>setter is called inside this method. this method calls the iBatis mappings. </p>
  
  <pre><code>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()&gt;=questionsToBeShown)
          setQuestions(local_questions.subList(0, questionsToBeShown));
      getRequest().getSession().setAttribute("questionsForUser", getQuestions());
  }
  </code></pre>