2010-07-19 77 views
1

我有一个使用Hibernate映射到表的简单POJO。这工作得很好。GWT的可序列化Hibernate数据对象RPC

我的问题是我想能够序列化对象,所以我可以通过电线为我的GWT-RPC调用。如果我的异步服务回报这个对象,我得到一个错误:

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.

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

谢谢。

回答

1

问题是,GWT没有找到注释和使用的类的源代码。 GWT需要该源代码,因为它必须将对象编译为JS。可以使用Gilead来做到这一点。 (以前称为Hibernate4GWT)

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?

的问题是不与Set,GWT可以很好序列通过其GWT-RPC集合。虽然在传输过程中,您会希望使用像HashSet这样的特定实现来允许它针对该特定实现进行优化,而不是通用接口。

+0

会试试这个。还发现这个其他的链接,这几乎是相同的问题。谢谢。 http://stackoverflow.com/questions/3183269/hibernate-and-serializable-entities – 2010-07-19 16:08:59

+0

谢谢,虽然我使用(至少现在)的推土机解决方案。我现在了解这个GWT JRE仿真库问题。 – 2010-07-19 19:56:59

2

我想补充我如何克服这个问题,序列化细节:

1 - 我有2个数据模型对象(这是可怕的,但我没有得到时间的学校项目清理它)。

// The persistent data model class 
public class PatientPersistent implements Serializable { 
    ... 

    Set<Prescription> patientPrescriptions; 

    ... 
} 

// The serializable over the wire (GWT-RPC) data model class 
public class Patient implements Serializable { 
    ... 

    Set<Prescription> patientPrescriptions; 

    ... 
} 

2-我用推土机映射持续性模型< ==到==>序列化数据类病人。像这样:

Patient thePatient = mapper.map(persistentObject, Patient.class); 

这位患者由我的异步服务发送回客户端。在这个映射之后,你可以看到患者有一个来自java.util的HashSet类型,而不是hibernate的不可序列化版本。