我們只是切換到Glassfish V2。我們現在在設置會話屬性時會出錯。setAttribute:不可序列化的屬性(Java對象序列化)
錯誤是:
java.lang.IllegalArgumentException: PWC2788: setAttribute: Non-serializable attribute
代碼是:
getRequest().getSession().setAttribute("questionsForUser", getQuestions());
getQuestions()僅僅是一個簡單的getter這是一個名爲 '家長行動' 的抽象類中....所以使getQuestions()一個序列化對象做我的課需要實現序列化的?:
public List getQuestions() {
return questions;
}
- 我們如何才能使這個對象 可序列化?
- 這是一個很好的做法,只將 序列化的對象在會話中(因爲Glassfish似乎需要 )?
- 會話有 交換在用戶序列化 對象之間的風險嗎?
編輯:我使用的ORM(iBatis的)
更多信息有關 「問題」
二傳手:
public void setQuestions(List questions) {
this.questions = questions;
}
設置器調用此方法中。此方法調用iBatis映射。
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());
}
對於有類似問題的人非靜態非瞬態字段:當你在列表上做一個子列表時,你可以找回沒有實現Serializable的RandomAccessList。所以解決方案是將所有內容添加到像ArrayList這樣的搜索列表中。 – Omnipresent 2009-11-02 21:51:49