Thursday, 2 October 2014

Hibernate - annotation mappings and misleading SerializationException

Took me a few hours to get to the bottom of this.
I was getting the following Exception, which did not make sense as the deSerialization test passed OK.
I have a domain object that I had proved through a unit test that I could serialize & deserialize successfully.


My domain object contained the following object which if I removed then worked OK:


But tomcat & my integration test were both failing with the following Exception.


It turns out I had missed out an annotation, obvious really but I could not spot the error & the Exception was totally misleading. What had I missed? The '@manyToOne' annotation. Twit.

1 comment:

Vance Blakely said...

Hey Bill, thanks very much for this post. I had the exact same issue and was totally confused by the error message that was produced.

After understanding the root cause of this issue, the error message does make a little more sense. It my case, the controller was failed to deserialize the object because of the missing annotation.

Once I added the ManyToOne annotation, everything work perfectly.

Thanks!