用于GWT RPC的可序列化Hibernate数据对象 [英] Serializable Hibernate data object for GWT RPC

查看:85
本文介绍了用于GWT RPC的可序列化Hibernate数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Hibernate映射到表的简单POJO。这可以工作得很好。

I have a simple POJO mapped to a table using Hibernate. Which works just fine.

public class Patient implements Serializable {

    private int    patientId;
    private String firstName;
    private String lastName;
    private Set<Prescription> patientPrescriptions;

    public Patient() {}

    ...
}

我的问题是我希望能够序列化对象,以便我可以通过GWT-RPC调用的线路来获取它。如果我的异步服务返回这个对象,我收到一个错误:

My problem is I want to be able to serialize the object so I can get it trough the wire for my GWT-RPC calls. If my async service return this object I get an error:


com.google.gwt.user.client.rpc.SerializationException:Type' org.hibernate.collection.PersistentSet'未包含在可由此SerializationPolicy序列化的类型集中,或者其Class对象无法加载。为了安全起见,这种类型不会被序列化。

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.

我想这是因为它不能序列化 Set ,因为这是一个接口,因此不可序列化。另一方面,Hibernate需要一个集合接口(Set / Map)来工作。那么这意味着我不能再发送使用Hibernate映射的对象了?有没有一些简单的方法来序列化一个集合?

I suppose this is due to the fact it cannot serialize Set since this is an interface hence not serializable. On the other hand Hibernate needs a collection interface (Set/Map) to work. So this means I can no longer send objects mapped with Hibernate? Is there some "easy" way to serialize a Set?

谢谢。

推荐答案

问题是GWT没有找到注释和使用的类的源代码。 GWT需要源代码,因为它必须将你的对象编译成JS。

The problem is that GWT does not find the source code of the annotations and the used classes. GWT needs that source code since it has to compile your object into JS.


我希望能够序列化
对象所以我可以通过
线为我的GWT-RPC调用获得它。

I want to be able to serialize the object so I can get it trough the wire for my GWT-RPC calls.

您可以使用 Gilead 来做到这一点。 (以前称为Hibernate4GWT)

You can use Gilead to do that. (Previously known as Hibernate4GWT)


我想这是因为它
无法序列化Set,因为这是
接口因此不可序列化。在
上另一方面Hibernate需要一个
集合接口(Set / Map)到
工作。所以这意味着我不能再
发送映射到Hibernate的对象了吗?是
有一些简单的方式来序列化一个
集?

I suppose this is due to the fact it cannot serialize Set since this is an interface hence not serializable. On the other hand Hibernate needs a collection interface (Set/Map) to work. So this means I can no longer send objects mapped with Hibernate? Is there some "easy" way to serialize a Set?

问题不在于code> Set ,GWT可以很好地通过它的GWT-RPC序列化集合。虽然在传输过程中,您将希望使用像 HashSet 这样的特定实现来优化特定实现,而不是通用接口。

The problem is not with Set, GWT can very well serialize collections through its GWT-RPC. Although during the transmission you will want to use a specific implementation like HashSet to allow it to optimize for that particular implementation, instead of a generic interface.

这篇关于用于GWT RPC的可序列化Hibernate数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆