I got the following exception (Hibernate 3.5.6):
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)
....
Caused by: java.io.StreamCorruptedException: invalid stream header: 35353530
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:328)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:318)
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:237)
...
Code:
@Entity @Table(name="problem")
public class Problem implements Serializable, Cloneable {
private Set<ProblemScreenMetaproperty> screenMetaproperties = new HashSet<ProblemScreenMetaproperty>();
@OneToMany(cascade=CascadeType.ALL,orphanRemoval=true,mappedBy="id.problem")
public Set<ProblemScreenMetaproperty> getScreenMetaproperties() {
return screenMetaproperties;
}
....
}
@Entity @Table(name="problem_screen_metaproperty")
public class ProblemScreenMetaproperty implements Serializable {
private ProblemScreenMetapropertyKey id;
@EmbeddedId
public ProblemScreenMetapropertyKey getId() {
return id;
}
...
}
@Embeddable
public class ProblemScreenMetapropertyKey implements Serializable {
private Problem problem;
private ScreenMetapropertyDefinition screenMetaproperty;
public Problem getProblem() {
return problem;
}
public ScreenMetapropertyDefinition getScreenMetaproperty() {
return screenMetaproperty;
}
....
}
I solved the issue by adding the following annotations to the Composite Key (ProblemScreenMetapropertyKey)
Code:
@Embeddable
public class ProblemScreenMetapropertyKey implements Serializable {
private Problem problem;
private ScreenMetapropertyDefinition screenMetaproperty;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="problem_id", unique=false, nullable=true, insertable=true, updatable=true)
public Problem getProblem() {
return problem;
}
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="screen_metaproperty_id", unique=false, nullable=true, insertable=true, updatable=true)
public ScreenMetapropertyDefinition getScreenMetaproperty() {
return screenMetaproperty;
}
....
}
So the issue is solved, but it seems to me that Hibernate may provide a more specific message about the issue to make troubleshooting easier.