1

我有3个类,推荐,判断,用户,关系是:一个推荐可能有多个判断,一个用户可能有多个判断(根据不同的推荐),这是我的JPA类:

班级推荐

@Entity
@Table(name = "RECOMMENDATIONS")
public class Recommendation implements Serializable, Cloneable {
...

@OneToMany(cascade = {CascadeType.REFRESH, CascadeType.DETACH }, fetch = FetchType.EAGER, mappedBy="recommendation", targetEntity=Judgement.class)
private Set<Judgement> judgements;

    ...
    public Recommendation() {
        super();
        this.judgements = new LinkedHashSet<Judgement>();
    }
   ...
}

班级用户:

@Table(name = "USERS", uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class User implements Serializable, Cloneable {
...
    @OneToMany(mappedBy="judge", targetEntity=Judgement.class, cascade = { CascadeType.REFRESH, CascadeType.DETACH }, fetch = FetchType.EAGER)
    private Set<Judgement> judgements;
...
    public User() {
        super();
        this.judgements = new LinkedHashSet<Judgement>();
    }

...
}

班级判断:

@Entity
@Table(name = "JUDGEMENTS")
public class Judgement implements Serializable, Cloneable {
    @ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.DETACH})
    @JoinColumn(name = "id")
    private Recommendation recommendation;

    @ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.DETACH})
    @JoinColumn(name = "user_id")
    private User judge;
...
    public Judgement() {
        super();
    }
...
}

在 db 中,我有以下表格:用户推荐;判断;

我在用户中有一些数据,在推荐中有一些数据,但在判断表中为空,当我加载我的应用程序时出现以下异常:

com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.collection.PersistentSet' 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 = []

我调试了加载推荐记录的判断字段时出现的代码,它无法实例化它。请帮忙!

4

1 回答 1

2

包含由 hibernate 加载的数据库实体的对象是不可序列化的。因此,它们不能用作 gwt 远程过程调用的传输对象。

最简单的解决方案是将实体实例(在您的情况下为推荐、判断和用户的实例)中的所有内容复制到简单的数据持有者对象中,并将持有者对象用作远程过程调用中的参数。对于小型项目,这是一个很好的解决方案。对于更大的项目,您可以考虑使用 Gilead 库;在这种情况下,您甚至可以从延迟加载中获益。

Google 提供了将 hibernate 集成到 GWT的良好文档。

于 2012-05-09T07:48:01.127 回答