为什么这个类不可序列化?

时间:2011-09-20 11:50:02

标签: java serialization

我有错误:

com.google.gwt.user.client.rpc.SerializationException: Type 'ru.xxx.empeditor.client.Dept$$EnhancerByCGLIB$$2f6af516' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = ru.xxx.empeditor.client.Dept@e53d4e

为什么这个课程不可序列化?

package ru.xxx.empeditor.client;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * Dept generated by hbm2java
 */
public class Dept implements IsSerializable {

    private byte deptno;
    private String dname;
    private String loc;
    private Set<Emp> emps = new HashSet<Emp>(0);

    public Dept() {
    }

    public Dept(byte deptno) {
        this.deptno = deptno;
    }

    public Dept(byte deptno, String dname, String loc, Set<Emp> emps) {
        this.deptno = deptno;
        this.dname = dname;
        this.loc = loc;
        this.emps = emps;
    }

    public byte getDeptno() {
        return this.deptno;
    }

    public void setDeptno(byte deptno) {
        this.deptno = deptno;
    }

    public String getDname() {
        return this.dname;
    }

    public void setDname(String dname) {
        this.dname = dname;
    }

    public String getLoc() {
        return this.loc;
    }

    public void setLoc(String loc) {
        this.loc = loc;
    }

    public Set<Emp> getEmps() {
        return this.emps;
    }

    public void setEmps(Set<Emp> emps) {
        this.emps = emps;
    }

}

1 个答案:

答案 0 :(得分:1)

检查班级Emp是否可串行。

另一个潜在的问题(因为你正在使用Hibernate - 注意到自动生成的注释)可能是因为代理修改了你的bean的字节代码,因此GWT无法序列化它。如上所述 - http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html