gpt4 book ai didi

hibernate - org.hibernate.type.SerializationException : could not deserialize

转载 作者:行者123 更新时间:2023-12-04 03:01:34 31 4
gpt4 key购买 nike

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

我有一个表用户

@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;
}
}

和一个 table 区
@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 - 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

最佳答案

我建议只在字段或 getter 上设置注释。我更喜欢田地,但这只是我的口味。

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.



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

关于hibernate - org.hibernate.type.SerializationException : could not deserialize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253403/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com