我正在使用GWT,Hibernate和Gilead,我没有摆脱序列化异常:
com.google.gwt.user.client.rpc.SerializationException: Type '[Ljava.lang.Object;' 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.
我正在Hibernate查询语言中进行加入,导致错误:
List<UserEvent> userEvents = session.createQuery(
"FROM UserEvent as userevent JOIN userevent.event as event WHERE userevent.user = ? AND userevent.status = 'JOIN' ORDER BY event.eventBegin ASC")
.setLong(0, user.getUserID()).setFirstResult(start).setMaxResults(maxResult).list();
这些类的代码是:
@Entity
public class UserEvent extends LightEntity implements Serializable {
private static final long serialVersionUID = -291120580889352994L;
@Id
@ManyToOne
@JoinColumn(name = "user_userid")
private User user;
@Id
@ManyToOne
@JoinColumn(name = "event_eventid")
private Event event;
@Enumerated(EnumType.STRING)
private EventStatus status;
private Long time;
public UserEvent() {
}
@Entity
public class Event extends LightEntity implements Serializable {
private static final long serialVersionUID = -2504468186803850440L;
@Id
@GenericGenerator(name = "event_seq", strategy = "webapp.hibernate.EventSeq")
@GeneratedValue(generator = "event_seq")
private Long eventID;
private Long eventBegin;
public Event() {
}
有人知道这方面的解决方案吗?
答案 0 :(得分:0)
你在这里看到的问题是由于
加载的对象query.list()
调用未加载UserEvents。它正在加载UserEvent的动态代理。 Hibernate使用代理对象来拦截对延迟加载的相关对象的调用。
有些图书馆可以提供帮助(EG http://www.jboss.org/errai)。
您可以做的另一件事是在尝试序列化之前将JPA实体转换为POJO,这应该确保代理不会妨碍它。