我想用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