java - Hibernate/hsqldb 2 Cannot Hydrate Blob Column -


i trying load entity byte data (annotated @lob) hsql 2.0 database using hibernate 3.5.6. entity able saved without problems , loaded fine if in cache (i.e. not need hydrated). however, when entity not in cache (needs hydrated), receive following exception:

caused by: org.hsqldb.hsqlexception: incompatible data type in conversion: sql type blob [b, value: instance of org.hsqldb.types.blobdataid     @ org.hsqldb.error.error.error(unknown source)     ... 68 more 

here full stack trace (minus domain specific trace) more context:

javax.persistence.persistenceexception: org.hibernate.exception.sqlgrammarexception: not execute query @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1235) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1168) ...  caused by: org.hibernate.exception.sqlgrammarexception: not execute query @ org.hibernate.exception.sqlstateconverter.convert(sqlstateconverter.java:92) @ org.hibernate.exception.jdbcexceptionhelper.convert(jdbcexceptionhelper.java:66) @ org.hibernate.loader.loader.dolist(loader.java:2452) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2192) @ org.hibernate.loader.loader.list(loader.java:2187) @ org.hibernate.loader.hql.queryloader.list(queryloader.java:452) @ org.hibernate.hql.ast.querytranslatorimpl.list(querytranslatorimpl.java:363) @ org.hibernate.engine.query.hqlqueryplan.performlist(hqlqueryplan.java:196) @ org.hibernate.impl.sessionimpl.list(sessionimpl.java:1258) @ org.hibernate.impl.queryimpl.list(queryimpl.java:102) @ org.hibernate.ejb.queryimpl.getresultlist(queryimpl.java:241) ... 45 more  caused by: java.sql.sqlsyntaxerrorexception: incompatible data type in conversion: sql type blob [b, value: instance of org.hsqldb.types.blobdataid @ org.hsqldb.jdbc.util.sqlexception(unknown source) @ org.hsqldb.jdbc.util.throwerror(unknown source) @ org.hsqldb.jdbc.jdbcresultset.getcolumnintype(unknown source) @ org.hsqldb.jdbc.jdbcresultset.getbytes(unknown source) @ org.hsqldb.jdbc.jdbcresultset.getbytes(unknown source) @ org.hibernate.type.abstractbynarytype.get(abstractbynarytype.java:103) @ org.hibernate.type.nullabletype.nullsafeget(nullabletype.java:186) @ org.hibernate.type.nullabletype.nullsafeget(nullabletype.java:175) @ org.hibernate.type.abstracttype.hydrate(abstracttype.java:105) @ org.hibernate.persister.entity.abstractentitypersister.hydrate(abstractentitypersister.java:2267) @ org.hibernate.loader.loader.loadfromresultset(loader.java:1443) @ org.hibernate.loader.loader.instancenotyetloaded(loader.java:1371) @ org.hibernate.loader.loader.getrow(loader.java:1271) @ org.hibernate.loader.loader.getrowfromresultset(loader.java:619) @ org.hibernate.loader.loader.doquery(loader.java:745) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:270) @ org.hibernate.loader.loader.dolist(loader.java:2449) ... 53 more caused by: org.hsqldb.hsqlexception: incompatible data type in conversion: sql type blob [b, value: instance of org.hsqldb.types.blobdataid @ org.hsqldb.error.error.error(unknown source) ... 68 more 

this problem did not occur when used hibernate 3.5.6 , hsql 1.8.0.10, because of different dialect used (blob column wasn't supported in hsql 1.8). version of hibernate i'm using supposed support hsql 2 , have checked detecting hsql version , using correct dialect. problem not occur when use mysql.

the entity in question has lob column set so:

@entity public class imageentity extends identity {      @lob     @column(name="image")     private byte[] imagebytes;     ... 

is hibernate/hsql 2.0 bug?

i found problem in jdbcresultset.java (hsqldb 2.0.0 downloaded sourceforge project) getbytes method. hsqldb 2.0 supports blob column 1.8.* doesn't, might bug haven't updated jdbc implementation. following patch getbytes method solves problem:

public byte[] getbytes(int columnindex) throws sqlexception {      type sourcetype = resultmetadata.columntypes[columnindex-1];     if (sourcetype.islobtype()){         blob b = getblob(columnindex);         return b.getbytes(1, (int)b.length());     }      object x = getcolumnintype(columnindex, type.sql_varbinary);      if (x == null) {         return null;     }      return ((binarydata) x).getbytes(); } 

original method was:

public byte[] getbytes(int columnindex) throws sqlexception {      object x = getcolumnintype(columnindex, type.sql_varbinary);      if (x == null) {         return null;     }      return ((binarydata) x).getbytes(); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -