我想用spring和hibernate开发一个小型的GWT应用程序,但在从MySql db获取列表时出现错误。实体类联系人与房间有@ManyToOne关系。GWT rpc.SerializationException在休眠ManyToOne关系对象
@Entity
@Table(name = "contact")
public **class Contact** extends LightEntity implements java.io.Serializable {
@Id
@Column(name = "id")
protected int id;
@Column(name = "firstname")
protected String firstname;
@Column(name = "telephone")
protected String telephone;
@ManyToOne
@JoinColumn(name = "ROOM_ID")
protected Room room;
... getter和setter方法
@Entity
@Table(name = "ROOM")
public **class Room** extends LightEntity implements java.io.Serializable {
@Id
@GeneratedValue
@Column(name = "ROOM_ID")
private int id;
@Column(name = "ROOM_NUMBER")
protected int rnr;
@OneToMany(mappedBy="room", fetch = FetchType.EAGER) // tried to fetch eagerly
private List<Contact> contacts;
...
LightEntity已作为第https://developers.google.com/web-toolkit/articles/using_gwt_with_hibernate?hl=fr-FR
expained getter和setter方法。当我只用单向方向(即与@ManyToOne联系到房间)的关系然后它工作正常。
这里是例外: -
Hibernate: select contacts0_.ROOM_ID as ROOM6_1_1_, contacts0_.id as id1_, contacts0_.id as id0_0_, contacts0_.email as email0_0_, contacts0_.firstname as firstname0_0_, contacts0_.lastname as lastname0_0_, contacts0_.ROOM_ID as ROOM6_0_0_, contacts0_.telephone as telephone0_0_ from contact contacts0_ where contacts0_.ROOM_ID=?
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException:
Type 'org.hibernate.collection.PersistentBag' 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 = [[email protected], [email protected], [email protected], [email protected], [email protected]]
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)
任何帮助或建议,将不胜感激。
亲切的问候, 阿比德
第一件事: 你有一个空的构造这个班? GWT序列化是强制性的。 – 2012-04-24 08:23:59
是的两个实体类都有空构造函数。 – user1227806 2012-04-24 08:36:31