Monday, October 04, 2004

Hibernate, PostgreSQL and Spring

Puh.. After couple of hours swearing at this problem, I finally found what caused the error. The problem was that when trying to insert data in a PostgreSQL table I kept getting errors for some of the rows I was trying to insert. The error message returned from Hibernate was something like "data integrity violated by SQL 'null'…" blah blah blah "… Call getNextException() to see the cause". The Spring Framework data access exception was reporting a DataIntegrityViolationException.

I therefore assumed that the problem had to do with the quality of the data I was attempting to insert, such as null values. The suspicion did not get any less by the fact that the source of the data was read from an Excel spreadsheet using POI.

When I finally got to my senses and traced the Hibernate code, I was able to see the "next exception", which did NOT have anything to do with null values. The problem was that once in a while the value of one cell contained a string of six characters instead of five as defined in the database schema :-( It would be nice if Hibernate could include this information in the returned error message. Please Gavin!

I have recently converted from MySQL to PostgreSQL, after been lobbied by Thomas Roka-Aardal and have found that PostgreSQL is much more intolerant and strict than MySQL, but after all I think that is OK.

No comments: