Hibernate: Could not deserialize - invalid stream header

For others with the same error (does not answer this exact question)

I experienced this error with hibernate 4.3 and 5.0.5 due to fields of type java.time.LocalDateTime, I have several entities using LocalDateTime, but only one of them caused the issue, I don't know why.

It was fixed by adding the following dependency:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>${hibernate.version}</version>
</dependency>

Regarding the kaba713 answer and converting java.time.* by Hibernate.

I use org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; and it works with Spring-Boot 1.5.4.

@Column(name = "order_date", nullable = false)
@Convert(converter = Jsr310JpaConverters.LocalDateTimeConverter.class)
private LocalDateTime orderDate;

And we don't need to write a custom converter.


The problem should be for the Geometry relation, it is mapped as a regular column so Hibernate try to map a simple Column to a Geometry object. I had a similar problem and the solution was to explicity define the relation, something like:

@OneToOne
@JoinColumn(name = "bbox")
private Geometry bbox;

This issue is happening when something cannot be deserialized (thank you, Captain Obvious). In your entity mappings the following looks suspicious:

@Type(type = "hstore")
@Column(name = "tags", columnDefinition = "hstore")
private Object2ObjectOpenHashMap<String, String> tags = new Object2ObjectOpenHashMap<String, String>(); 

@Column(name = "bbox")
private Geometry bbox;

@Column(name = "linestring")
private Geometry linestring;

My suggestion is either to take a look over Geometry and Object2ObjectHashMap classes - check whether they are serializable itself and all their fields either serializable too, or marked with transient keyword. Also if you post these classes here, this may help aswell. HstoreUserType class listing may also be helpful.