Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.type.SerializationException: could not deserialize

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
like image 366
Shinigami Avatar asked Nov 06 '12 14:11

Shinigami


2 Answers

You can simply annotate above any field of joda time:

   @Temporal(TemporalType.DATE)
   @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
like image 120
Dejell Avatar answered Sep 19 '22 09:09

Dejell


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.

like image 26
Christian Avatar answered Sep 21 '22 09:09

Christian