3 Replies Latest reply on Dec 8, 2004 1:21 PM by dhartford

    Problem with saving BINARY data with CMP

    thl-mot

      Hi,
      I'd like to store files in he database (SQL-Server). The File data itself is stored in a array byte[]. The entity attribute is an Object. The database column type is image.
      I have no problem with storing the data. But when reading the entity data from the database I get the following exception

      2004-12-08 14:59:27,453 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.Integer de.netpioneer.jchms.entities.ChangeRequestComment.getChangeRequestCommentID(), causedBy:
      java.sql.SQLException: Unable to load to deserialize result: java.io.StreamCorruptedException: invalid stream header
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.convertToObject(JDBCUtil.java:291)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.access$500(JDBCUtil.java:53)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil$6.readResult(JDBCUtil.java:585)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil$AbstractResultSetReader.get(JDBCUtil.java:400)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadArgumentResults(JDBCAbstractCMPFieldBridge.java:424)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadInstanceResults(JDBCAbstractCMPFieldBridge.java:373)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:188)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:72)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:612)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:594)
      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:381)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:352)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:239)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:114)


      What JDBC_TYPE do I have to configure in jbosscmp_jdbc.xml for the column. I already tryed BLOB, but this type wasnt supported by the driver.

        • 1. Re: Problem with saving BINARY data with CMP
          dhartford

          Hey thl-mot,
          If the problem is the JDBC_TYPE, you may want to look at VARBINARY. The jdbc types don't seem to be as standardized as one may hope.

          I personally configured the entity to also be a byte[], and the database column as a BLOB, and this works fine (it makes it large, but at least can assure the Data Transfer Objects work as expected). It looks like it is trying to stream the data, so even though it may be an 'Object', it may actually be trying to use it as a java.io. Input/OutputStream.

          Hope that helps!

          FYI - recommend you take a look at a WebDAV server for storing documents/images such as http://jakarta.apache.org/slide

          Maintains J2EE compliance without storing the data in BLOBs in the database, plus get to stream the data ;-)

          -D

          • 2. Re: Problem with saving BINARY data with CMP
            thl-mot

            Hey,
            In your case, does the database contain the serialized array obejct or the byte values from the array?

            • 3. Re: Problem with saving BINARY data with CMP
              dhartford

              The database (with byte[] entity field and BLOB database column) stores the data as real byte data, not a serialized java object. As such, you can store and retrieve the BLOB to/from normal binary file manipulation using tools/languages other than Java.

              -D