Sh*t my brain says and forgets about

Hibernate 3.6.0.Final + PostgreSQL + CLOBs

I recently upgraded a project I’m working on to Hibernate 3.6.0.Final from 3.5.6 and realized that one of my entities that had a CLOB (character large object) was pooping out.  I was getting an exception stack track similar to:

Caused by: org.postgresql.util.PSQLException: Bad value for type long : <table border="0" cellspacing="0" cellpadding="0" id="productDetailLineItems"><thead><tr><td rowspan="2"><input type="hidden" name="productGroupId" id="productGroupId" value="101111"/>Item Number</td><td rowspan="2">Motor HP</td><td rowspan="2">Price</td></tr></thead><tbody><tr><form method="post" id="4581000" name="4581000" action=""><td>4581000</td><td><span style="fraction"><sup>1</sup>/<sub>2</sub></span></td><td><input type="button" onclick="javascript:addToCart('4581000');" value="$prc4581000" /></td></form></tr></tbody></table>
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong( [:]
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong( [:]
at org.postgresql.jdbc3.Jdbc3ResultSet.getClob( [:]
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob( [:]
at org.jboss.resource.adapter.jdbc.WrappedResultSet.getClob( [:6.0.0.Final]
at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$2.doExtract( [:3.6.0.Final]
at org.hibernate.type.descriptor.sql.BasicExtractor.extract( [:3.6.0.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet( [:3.6.0.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet( [:3.6.0.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet( [:3.6.0.Final]
at org.hibernate.type.AbstractStandardBasicType.hydrate( [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate( [:3.6.0.Final]
at org.hibernate.loader.Loader.loadFromResultSet( [:3.6.0.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded( [:3.6.0.Final]
at org.hibernate.loader.Loader.getRow( [:3.6.0.Final]
at org.hibernate.loader.Loader.getRowFromResultSet( [:3.6.0.Final]
at org.hibernate.loader.Loader.doQuery( [:3.6.0.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections( [:3.6.0.Final]
at org.hibernate.loader.Loader.loadEntity( [:3.6.0.Final]
... 167 more

I do local development on my MacBook Pro with PostgreSQL 9.0.2 and will point my machine at the client’s DB2 database once in a while for pushes to their development system.  When I point the system at their DB dev database, everything works fine.  Pointing back at my PostgreSQL, the entity craps out.  I tried going back to the old 8.0 driver like some people online suggested with no luck.  I hadn’t tried using this entity since I upgraded to Hibernate 3.6 because I also have been moving from OpenEJB to JBoss 6 so it could have been that as well.

Ultimately I found a simple solution.  PostgreSQL apparently doesn’t play well with Hibernate 3.6 and requires a specific Hibernate annotation on your entity (I’m using JPA entities by the way).  On your CLOB, in addition to the @Lob, add:


Redeploy your application and Hibernate should behave properly.


Installing MySQL 5.5.8 on Mac OS X Snow Leopard


CDMA / Verizon iPhone

1 Comment

  1. Xin Zoo

    I encountered exactly this problem today when i migrated from Tomcat and Hibernate 3.4 to JBoss 6.
    Thanks Aaron!

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress & Theme by Anders Norén