Archive

Archive for the ‘Hibernate’ Category

Hibernate Bites Me Again (My fault though)

December 10th, 2009 Chris Hane 4 comments

Love hibernate / hate hibernate.

I love it because we have not had to code boilerplate SQL in.. well … years. It gives us all kinds of flexibility and quick application development.

There are times I hate it though (that might be too strong). We are in the process of converting a large app and upgrading the UI. At the same time, we are removing all of the technical debt we have built up over time. Today we found a bug and the error from hibernate was:

org.hibernate.type.SerializationException: could not deserialize

Not very helpful. Turns out we are not the only ones who have had this issue. Gotta love search!

The gist of everyone’s problem is incorrect mappings. Once we were able to turn on debuging, we narrowed it down to a class and then to the specific field. Once we corrected the mapping, all was good with the world again.

Now you might look at this and wonder why it was such a big deal. We’ll, what was an hour exercise, should have been 5 minutes at most (the actual fix was 10 seconds once identified). First, the issue was we were missing a mapping in the configuration file (the mapping was correct on the object). So I would have though it would have been caught during hibernate startup. The actually problem was a missing @Type declaration for an enum.

At worst, the error message should be better in Hibernate (we are working with 3.3.2.6) – hibernate knows which object/property it had issues with.

Anyway, moral of the story is to always check your field mappings and the config file to make sure it is correct also.

Update:
Found another gotcha (again my fault). Watch association mappings. My index property on a list mapping was being updated with null. I had the following:

   @OneToMany(mappedBy = "form")
   @IndexColumn(name="sequence", base=0)
   public List<FormField> getFields(){
      return fields;
   }

It should have been:

   @OneToMany
   @JoinColumn(name = "form")
   @IndexColumn(name="sequence", base=0)
   public List<FormField> getFields(){
      return fields;
   }
 
Categories: Hibernate, Java