Mike Adler
Mike Adler

Reputation: 1200

Loading BLOB table from H2 embedded with Hibernate

I have an application that has to run with an Oracle or embedded H2 database depending on the environment. Up till now I used a MySQL database instead of the embedded H2 one, but decided to migrate.

I use Hibernate 3.3.1GA (and am restricted, so I cannot update). With both Oracle and MySQL everything works fine, but when I try to use the H2 database it keeps hanging. The problem appears to be a column with BLOBs (serialized java objects). Even when the table is empty, execution hangs.

SLF4J output (loglevel ALL):

TableMetadata.java:org.hibernate.tool.hbm2ddl.TableMetadata:<init>:62 INFO  table found: DATABASE.PUBLIC.JAVA_OBJECTS
org.hibernate.tool.hbm2ddl.TableMetadata:<init>:63 INFO  columns: [id, last_update, markdeleted, class, object]
org.hibernate.connection.DriverManagerConnectionProvider:closeConnection:152 TRACE returning connection to pool, pool size: 1

At this point the program seems to hang. Earlier log output seems normal and when this table is not used (removed from hibernate.cfg.xml) the program starts up fine.

hibernate.cfg.xml (excerpt)

<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:file:database</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.default_schema">PUBLIC</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

The table's create string:

CREATE TABLE java_objects (
  id int(11) NOT NULL AUTO_INCREMENT,
  class varchar(255) NOT NULL,
  object blob NOT NULL,
  last_update timestamp AS CURRENT_TIMESTAMP,
  markDeleted tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (id)
) ;

and finally the entity xml

<hibernate-mapping>
    <class name="server.DataBean" table="java_objects">
        <id name="id" column="id">
            <generator class="native" />
        </id>
        <property name="type" column="class" />
        <property name="object" not-null="true">
            <column name="object" sql-type="BLOB" />
        </property>
        <property name="lastUpdate" column="last_update" type="timestamp" />
        <property name="markDeleted" type="boolean" />
    </class>
</hibernate-mapping>

Does anyone know what I'm doing wrong? What is h2 expecting differently when handling blobs?

Upvotes: 1

Views: 2357

Answers (1)

Mike Adler
Mike Adler

Reputation: 1200

Problem may have been with org.hibernate.dialect.H2Dialect

Changing to HSQLDialect works. Still, is there an underlying issue?

Upvotes: 1

Related Questions