fetching blobs(byte[]) using OpenJPA fails

45 views
Skip to first unread message

Prashant Bhat

unread,
Jan 10, 2008, 1:21:22 AM1/10/08
to H2 Database
Hi Thomas,

I've an entity with a property of type byte[] which is mapped as blob.
I use it store a file as an attachment. When persisting the new
entity, it works fine but when the same object is being loaded, it
fails, because H2Dictionary has 'useGetObjectForBlobs' set to true,
whereas the default in DBDictionary is false. I changed it to false
and is working for me!

The 'getBytes' method uses 'rs.getObject(column);' which fails with
the following exception:

Caused by: java.lang.ClassCastException: java.io.ByteArrayInputStream
cannot be cast to [B
at
org.apache.openjpa.jdbc.sql.DBDictionary.getBytes(DBDictionary.java:
531)
at
org.apache.openjpa.jdbc.sql.ResultSetResult.getBytesInternal(ResultSetResult.java:
278)
at
org.apache.openjpa.jdbc.sql.ResultSetResult.getObjectInternal(ResultSetResult.java:
404)
at
org.apache.openjpa.jdbc.sql.AbstractResult.getObject(AbstractResult.java:
662)
at
org.apache.openjpa.jdbc.meta.strats.HandlerStrategies.loadDataStore(HandlerStrategies.java:
205)
at
org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy.load(HandlerFieldStrategy.java:
172)
at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:
796)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:
841)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:
793)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:
483)
at
org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:
116)
at
org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:
78)
at
org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:
2893)
at
org.apache.openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:
2971)
at
org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:
1476)
at
org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:
1461)

So is it safe to change 'useGetObjectForBlobs' property to false? If
so, I can create a jira issue in OpenJPA to get it updated:-)

Thanks,
Prashant

P.S. I'm using the latest snapshot of OpenJPA and H2-1.0.64

Thomas Mueller

unread,
Jan 11, 2008, 4:42:42 AM1/11/08
to h2-da...@googlegroups.com
Hi,

H2Dictionary has 'useGetObjectForBlobs' set to true

You are right, as far as I read in the OpenJPA source code, it's better to switch this flag off.

So is it safe to change 'useGetObjectForBlobs' property to false? If
so, I can create a jira issue in OpenJPA to get it updated:-)

That would be great of course! Yes, switching this flag off is save in my view.

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages