Gwt 服务端使用hiberante 问题解决

Gwt 服务端使用hiberante 问题解决


使用hibernate,在返回前端时,会出现一些错误,如lazy装载、还有就是hibernate对实体类的多种状态,在返回前端都会出错。

下面是List的解决方法


package com.google.gwt.user.client.rpc.core.org.hibernate.collection;

import java.util.Iterator;

import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;

/**
 * Custom field serializer for { @linkorg.hibernate.collection.PersistentList}.
 */
public final class PersistentBag_CustomFieldSerializer {

 public static void deserialize(SerializationStreamReader streamReader,
   org.hibernate.collection.PersistentBag instance)
   throws SerializationException {
  int size = streamReader.readInt();
  for (int i = 0; i < size; ++i) {
   Object obj = streamReader.readObject();
   instance.add(obj);
  }
 }

 public static void serialize(SerializationStreamWriter streamWriter,
   org.hibernate.collection.PersistentBag instance)
   throws SerializationException {
  int size = instance.size();
  streamWriter.writeInt(size);
  Iterator iter = instance.iterator();
  while (iter.hasNext()) {
   Object obj = iter.next();
   streamWriter.writeObject(obj);
  }
 }

}

你可能感兴趣的:(Hibernate,Google,gwt)