开发者

JPA[Hibernate] Lazy-loading with GWT problem

I'm trying to use lazy-loading JPA[Hibernate] with GWT front-end

In entity

 @ManyToOne(targetEntity = Item.class,fetch=FetchType.LAZY)
 private Item item;

In dao

 @Transactional
 public List<Purchase> findAllPurchases() {
   return jpaTemplate.execute(new JpaCallback<List<Purchase>>(){
   public List<Purchase> doInJpa(EntityManager em)
    throws PersistenceException {
    List<Purchase> list = em.createQuery("select o from Purchase o").getResultList();
    for(Purchase p:list){
     Item item = p.getItem();
     if(item!=null)
     item.getItemName();
    }
 return list;
}

}); }

and I receive this error.

com.google.gwt.user.client.rpc.S开发者_如何学GoerializationException: Type 'com.hardwarestore.vo.Item_$$_javassist_0' 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.hardwarestore.vo.Item@a1eaf6

Both Purchase class and Item class implements Serializable interface. Any kind of help is appreciated. Thank you.


Or, you can use DTO (Data transfer object). Just transform the persisted object in the server side before sending it to client side.


The serializer in GWT is unable to serialize the Proxy-Object of your Collection, because its Class is created at runtime in your server-part. To serialize an deserialize, the ProxyObject sources must be found at compiletime (I think).

As far as I anderstand the process of serializiation in GWT you are unable to make lazy-loading. You have to transform your entities in that way, that you create a callable methode, which loads the collection from JS by the primary key of your Entity which holds the collection or you have to switch the collection to eager-loading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜