org.hibernate.type.SerializationException:无法反序列化 [英] org.hibernate.type.SerializationException: could not deserialize

查看:1666
本文介绍了org.hibernate.type.SerializationException:无法反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Hibernate和
的两个表我不明白为什么特定的查询我有这个问题。
我希望有人认识到这个问题。



我有一个表用户

 code> @Entity 
@Table(name =user)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long idUser;
私人区域;

//...other get和setter

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name =idarea)
public Area getArea(){
return area;
}
}

和一个表区域

  @Entity 
@Table(name =area)
public class Area implements Serializable {
private static final long serialVersionUID = 1L;

@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name =idarea)
private Long idArea;

@Column(name =area_name)
private String areaName;

@Column(name =time_start)
private LocalTime timeStart;

//...other get and setter

}

LOGS说:

  15:27:28,140 INFO DefaultLoadEventListener:160  - 执行加载命令
时出错org.hibernate.type.SerializationException:无法反序列化
在org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:262)
在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java :306)
在org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:130)
在org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java :116)
at
.... //其他行
org.springframework.orm.hibernate3.HibernateSystemException:无法反序列化;嵌套异常是org.hibernate.type.SerializationException:无法反序列化


解决方案

我建议仅在字段或getter上设置注释。我喜欢这些领域,但这只是我的口味。



请参阅 Hibernate中的字段和属性访问的好奇情况


因此,只能将注释放在字段上,或者仅在getter(属性)上放置。混合它们而不使用@Access将会导致异常行为。


然后,如果序列化是应用程序的一部分,我建议生成更好的serialVersionUID使用工具。


I'm using two tables by Hibernate and I dont understand why for particular query I have this problem. I hope someone recognizes the problem.

I have a table user

@Entity
@Table(name="user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long idUser;
private Area area;

//...other get and setter

@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="idarea")
public Area getArea() {
return area;
}
}

and a table area

@Entity
@Table(name = "area")
public class Area implements Serializable {
private static final long serialVersionUID = 1L;

@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="idarea")
private Long idArea;

@Column(name="area_name")
private String areaName;

@Column(name="time_start")
private LocalTime timeStart;

//...other get and setter

}

LOGS says:

15:27:28,140  INFO DefaultLoadEventListener:160 - Error performing load command
org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:262)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:306)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:130)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:116)
at 
....//other lines
org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize

解决方案

I would recommend to set the annotations only on the fields or the getters. I prefer the fields, but thats just my taste.

See The Curious case of Field and Property Access in Hibernate:

Thus either place the annotations on the fields only or on the getters(properties) only. Mixing them and not using @Access will cause abnormal behaviour.

Then if serialization is part of your application I would recommend to generate better serialVersionUID with a tool.

这篇关于org.hibernate.type.SerializationException:无法反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆