GWT JPA - The response could not be deserialized

2020-07-25 03:09发布

I use GWT and JPA for persistence. I have created a domain JPA enchanted classes, DAO's and RPC for communication between them. Everything works fine, through RPC the client sends the object to server but could not get response. Server cannot deserialize in a compatible way with the client side. So i cannot use the server callBack back to the client. The exception message is this:

The response could not be deserialized, com.google.gwt.user.client.rpc.SerializationException

Here's a sample code of one of my classes:

@Entity
@Table(name="course")
public class Course implements Serializable {
    private static final long serialVersionUID = 1L;
    private int courseId;
    private String name;
    private List<Group> groups;
    private List<Module> modules;

    public Course() {
    }


    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(unique=true, nullable=false)
    public int getCourseId() {
        return this.courseId;
    }

    public void setCourseId(int courseId) {
        this.courseId = courseId;
    }


    @Column(nullable=false, length=100)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }


    //bi-directional many-to-one association to Group
    @OneToMany(mappedBy="course", fetch=FetchType.LAZY)
    public List<Group> getGroups() {
        return this.groups;
    }

    public void setGroups(List<Group> groups) {
        this.groups = groups;
    }


    //bi-directional many-to-one association to Module
    @OneToMany(mappedBy="course", fetch=FetchType.LAZY)
    public List<Module> getModules() {
        return this.modules;
    }

    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

}
  • If i remove the relationships it work's fine. This is done because collections like lists, set's e.t.c are converted into hibernate objects that cannot be handled by GWT client side.

标签: java gwt jpa
5条回答
干净又极端
2楼-- · 2020-07-25 03:28

I used Gilead and it fixed the issue.

Please check the corresponding post: GWT with JPA

查看更多
神经病院院长
3楼-- · 2020-07-25 03:32

If you're using GWT-RPC, make sure that all of the classes you're trying to serialize have a public default (no-argument) constructor and implement Serializable. If you have embedded classes, they must also have a no-arg constructor.

查看更多
相关推荐>>
4楼-- · 2020-07-25 03:41

got it working...after a redeploy of war again...strange..cant point to one specific thing (as i did clear browser cache/eclipse classes output/restart eclipse) Apparently workaround seems to be try redeploying webapp whenever this issue occurs..

查看更多
贼婆χ
5楼-- · 2020-07-25 03:43

Well the problem is that my class has @OneToMany association to another class. If i remove the association it work's fine. But it's impossible to that, since I use a normalized relational database

查看更多
在下西门庆
6楼-- · 2020-07-25 03:50

Once , I have prepared gwt-jpa sample for this question. It is just serialization of JPA entity.. It might give you a clue about what is wrong in your case..

查看更多
登录 后发表回答