2

spring と hibernate を使用して小さな GWT アプリケーションを開発したかったのですが、MySql db からリストを取得中にエラーが発生しました。エンティティ クラス Contact は、Room と @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;

...セッターとゲッター

@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で説明されているように使用されています

一方向(つまり、@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 = [com.project.server.schema.Contact@168e461, com.project.server.schema.Contact@dde1f6,  com.project.server.schema.Contact@c66a3b, com.project.server.schema.Contact@8103d8, com.project.server.schema.Contact@137dfac]
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)

ヘルプやアドバイスをいただければ幸いです。

よろしく、 アビッド

4

1 に答える 1

0

私にとって、この問題は@LazyCollectionを使用したときに消えました。

@LazyCollection(LazyCollectionOption.FALSE)

完全な例:

@ManyToOne(cascade = CascadeType.MERGE, optional=false)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name="room_id")
public Room getRoom();

@OneToMany(mappedBy = "contact")
@LazyCollection(LazyCollectionOption.FALSE)
public List<Contact> getContacts();
于 2012-04-24T10:59:12.000 に答える