20 May 2011

HSQLDB 2.0.0, BLOB & Hibernate

Written by ilgrosso

HSQLDB is a very nice and complete all-Java DBMS, particularly useful when doing quick test-outs or maven tests.
A while ago, a bug has been discovered in release 2.0.0 that is causing issues with BLOB management: this is a considerable issue especially with @Lob fields in Hibernate.
The bug was actually fixed in 2.1.0; latest stable release is by today 2.2.1.
Unfortunately, the latest release available at the Maven Central Repository is "only" 2.0.0. [Update: release 2.2.4 is now available (June 25th 2011)]
Taking inspiration from this StackOverflow question, I've elaborated a simple solution working for Hibernate.
First of all, create a simple Java class like as the following:

              public class HSQLSafeDialect extends HSQLDialect {

              public HSQLSafeDialect() {

              registerColumnType(Types.BLOB, "longvarbinary");
              registerColumnType(Types.CLOB, "longvarchar");

Then configure your Hibernate instance to use *.HSQLSafeDialect instead of standard org.hibernate.dialect.HSQLDialect.
Basically, this disables BLOB and CLOB supported introduced as new in HSQLDB 2.0.0, reverting to 1.8.X style.
Not fancy, but enough to make your maven tests run smoothly. Enjoy.


« Return