简体   繁体   中英

Why this class not serializable?

I have error:

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

Why this class not serializable?

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;
    }

}

Check if the class Emp is serialiable.

Another potential issue (since you are using Hibernate - noticed the auto-generated comment) could be because of Proxies that modify your bean's byte code, as a result of which GWT fails to serialize it. As mentioned here - http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM