Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize

Tags:

hibernate

jpa

When executing a Criteria Query in hibernate, I get the following exception:

javax.persistence.PersistenceException: javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize: could not deserialize

What could be the problem?

PS: although possibly not relevant, my hibernate version is hibernate-4.0.1 final.

like image 340
V G Avatar asked Jan 30 '14 17:01

V G


2 Answers

The problem was that a referenced entity had another reference to an entity and the relationship was NOT annotated by any of the @OneToMany-like annotations.

like image 84
V G Avatar answered Sep 22 '22 11:09

V G


This exception may occur when hibernate obtains data of unexpected type from database query result. For example hibernate expects number but gets string instead.

In such case look for StreamCorruptedException: "invalid stream header": 74657374 exception in stacktrace. The number is hint for you, but you may want to convert it to text with ascii table. 74657374 gives test as string. Which was value of similarly named table column, but with completely different type. So hibernate was querying wrong column which happened to exist just by chance, so the first exception raised was not column does not exist but could not deserialize instead. Hibernate was expecting long but got String instead.

I got in this mess because correct @Column(name="id_user") was ignored and hibernate infered wrong column name user from field name which wasn't idUser but just user with getUser() getter. The annotation was ignored because it was specified on property getter instead of the field, which was expected by hibernate because the entity superclass annotated ID field with @Id, instead of the ID getter, which is what I groundlessly expected.

like image 24
Vlastimil Ovčáčík Avatar answered Sep 22 '22 11:09

Vlastimil Ovčáčík