0 Replies Latest reply on Mar 25, 2004 5:00 PM by Jerrold Eads

    Creating beans with blob data members

    Jerrold Eads Newbie

      I am creating beans that have blob data members. I am using an oracle 8i database and JBoss 3.2.3. When create() is called on a bean with a blob member I get the following error:

      Initializing testBasesBean.
      2004-03-25 16:53:53,234 DEBUG [org.jboss.ejb.plugins.LogInterceptor] InvokeHome: create(-897206490,exoo,-27605,11001,com.synapps.j2eeutility.valueobjectbase.VOBlob@1f02eaa,1XXEEEE:::WWW222NNNEEEEWWWMMMTTT444QQQQFFF333YYYGGGkkkkaaaMMMCCCyyyppppCCCRRReee\\\wwwwmmmYYYOOOlll2222EEE;;;qqqhhh9999yyyLLL[[[oooeeee;;;111g^00;;;JJJAAA\\\\SSSCCCOOOVVV1111___UUUCCC```UUUUBBB888YYYOOObbbbWWWDDDOOOlllbbbbNNNDDDXXXQQQnnnn333PPPGGGxxxnnnnH,11370,-724161430,mmmttt:::VVVVMMM999yyyBBB7777TTTccc666vvv2222YYY<<<111NNNVVVVMMM999yyyLLLBBBB???555QQQGG4444YYYEEE<<<DDD;;;;[[[QQQnnn333PPPPGGGnnneeePPPGGGGddd]]]000pppSSSSIII000qqqCCCSSSSZZZfff222sss____UUUrrr000<<>>5555PPPGGGNNNYYY<<<<111NNNDDDJJJAAAAHHH,-5477,-1101600101,Fri Mar 12 22:53:47 CST 2004,Sat Mar 13 21:07:35 CST 2004,Sat Mar 13 21:07:35 CST 2004,Sat Mar 13 21:07:35 CST 2004,21637,21637,21637,-30694,-30694,-30694,H>>>ZZZPPP===MMMMJJJUUU\\\TTTTJJJggg\\\]]]VVVVsssjjjUUULLLhhhh===333___UUUrrrrlll???555kkkaaaa???555<<<aaahhhhuuuKKKAAAmmmdddd666AAAHHH???ttttkkkCCC:::WWWLLLL999___JJJAAASSSSIII666FFFMMMYYYY___;;;CCCVVVMMMM999___LLL[[[bbbbXXX;;;111cYYYvvv;;;;XXXRRRAAA777m,mmmddd666AAAHHHmmmmkkkwwwMMMCCC0000pppBBB777JJJAAAAwwwmmm@@@OOO<<<<222EEE;;;CCC0000VVVBBB999???5555YYY444;;;111bbbbYYYDDD;;;NNNHHHHeee[[[GGG===nnnneeexxx===ZZZPPPPqqqgggSSSIII\\\\ggg0000fff]]]333sssYYYYiii;;;222PPPWWWW222999yyy\\\RRRR???444QQQFFF3333YYY;;,1,1146102973,1152258956,22NNN^^^^KKK@@@],Wed Apr 07 13:47:07 CDT 2004,Wed Apr 07 13:47:07 CDT 2004,Wed Apr 07 15:29:43 CDT 2004,SS5555\\\HHH>>>ZZZ::::WWWMMM@@@666SSSS^^^111@@@]]]SSSSjjj```333BBB____333sssFFFVVViiii___555vvvaaaXXXXuuu555III?ukkkAAA888UUUUdddSSSJJJ555[[[[GGG>>>ZZZ:::MMMMDDD___VVVAAA7777TTTJJJ]]]SSSYYYYPPP;;;222999WWWWMMM```VVVBBBRRRRYYYOOO;;;111kkkkvvvIIIXXXuuukkkkA,AA888KKKZZZwwww888???KKKkkkwwwwttt:::WWWfff9999yyyKKKAAATTT0006666FFF333YYYEEE;;;oeGGG>>>^^^^jjjqqqLLLSSSJJJJNNNDDD000pppwwww===YYYPPP222rrrrFFFMMMZZZyyy<<<<CCCRRR666uuuHHHH>>>YYYPPP<<<2222EEEUUUBBB888TTTJ777\\\\eee[[[GGG>>>^^^^jjjqqqLLLJJJTTTTqqqhhhSSSJJ,null,null,null)
      2004-03-25 16:53:53,234 DEBUG [com.genecodes.oracle8iseqcol.lane.LaneBean] setEntityContext
      2004-03-25 16:53:53,328 DEBUG [com.genecodes.oracle8iseqcol.lane.LaneBean] ejbCreate
      2004-03-25 16:53:53,343 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand.Oracle8iSeqCol_Lane] Executing SQL: {call INSERT INTO LANE (ID, LANE_TYPE, APPLICATION_CREATOR, AUTO_ANALYSIS, AUTO_PRINT, LAST_USED, NAME, LANE_NUMBER, STATUS, THUMBPRINT, PRIMER_POSITION, RAW_DATA_START_POINT, START_EP, END_EP, START_EP_ANALYSIS, END_EP_ANALYSIS, INITIAL_SCAN_START, INITIAL_SCAN_END, LAST_SCAN_START, LAST_SCAN_END, CUSTOM_SCAN_START, CUSTOM_SCAN_END, START_COMMENT, STOP_COMMENT, ADAPTIVE_WORKED, AVERAGE_SPACING, CALCULATED_SPACING, ANALYSIS_VERSION, DATE_UPLOADED, SAMPLE_CREATION, SAMPLE_MODIFICATION, COLLECTION_SIZE_STD_NAME, COLLECTION_ANALYSIS_PARMS_NAME, SIGNAL_PROCESS_ID, RUN_ID, SAMPLE_ID) VALUES (LaneSeq.NEXTVAL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING ID INTO ? }
      2004-03-25 16:53:53,484 ERROR [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand.Oracle8iSeqCol_Lane] Could not create entity
      java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested

      at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)


      I have implemented a wrapper class for the java.sql.blob data, voblob which is used to populate the blob member:

      /*=============================================================================
      Copyright © 2002 SynApps Software Inc. All rights reserved.
      Project: J2EE Utiilities

      $Source: /home/cvs/synapps/SynApps/ValueObjectBase/src/com/synapps/j2eeutility/valueobjectbase/VOBlob.java,v $
      $Author: brian $
      $Date: 2002/11/06 21:37:34 $
      $Revision: 1.3 $
      =============================================================================*/
      package com.synapps.j2eeutility.valueobjectbase;

      import java.io.*;
      import java.sql.*;
      import java.math.BigInteger;
      import org.apache.log4j.Category;


      /**
      * Implementation for IVOBlob for use in VO's
      *
      * < p>Title: Generic Value Object< /p>
      * < p>Description: Base ValueObject Interface, Abstract Class, Object Factory,
      * Base Blob Interface and VOBlob Class implementation< /p>
      * < p>Copyright: Copyright (c) 2002 SynApps Software Inc. All rights reserved.< /p>
      * < p>Company: SynApps Software Inc.< /p>
      * @author Jerrold E Eads
      * @version $Revision: 1.3 $, $Date: 2002/11/06 21:37:34 $
      */
      public class VOBlob implements IVOBlob, Serializable {

      /**
      * Log4J log for exception logging
      */
      private static Category log =
      Category.getInstance(VOBlob.class);

      public byte[] data = null;

      /**
      * Constructor
      *
      * @param data byte array
      */
      public VOBlob(byte [] data)
      {
      this.data = data;
      }

      /**
      * Copy Constructor
      *
      * @param blob VOBlob
      */
      public VOBlob(VOBlob blob)
      {
      this(blob.data);
      }

      /**
      * int array Constructor
      *
      * @param intArray int array
      */
      public VOBlob(int [] intArray)
      {
      int arrayBoundary = intArray.length * 4;

      byte [] convertedBytes = new byte[arrayBoundary];
      int byteIndex = 0;
      for (int i = 0; i < intArray.length; ++i)
      {
      convertedBytes[byteIndex++] =
      (byte) ((intArray & 0xff000000) >>> 24);
      convertedBytes[byteIndex++] =
      (byte) ((intArray
      & 0x00ff0000) >>> 16); // the upper bits are truncated at cast
      convertedBytes[byteIndex++] =
      (byte) ((intArray & 0x0000ff00) >>> 8); // idem
      convertedBytes[byteIndex++] =
      (byte) ((intArray
      & 0x000000ff)); //idem
      }
      this.data = convertedBytes;
      }

      /**
      * short array Constructor
      *
      * @param shortArray short array
      */
      public VOBlob(short[] shortArray)
      {
      int arrayBoundary = shortArray.length * 2;

      byte [] convertedBytes = new byte[arrayBoundary];
      int byteIndex = 0;
      for (int i = 0; i < shortArray.length; ++i)
      {
      convertedBytes[byteIndex++] =
      (byte) ((shortArray & 0x0000ff00) >>> 8); // idem
      convertedBytes[byteIndex++] =
      (byte) ((shortArray
      & 0x000000ff)); //idem
      }
      this.data = convertedBytes;
      }

      /**
      * long array Constructor
      *
      * @param longArray long array
      */
      public VOBlob(long [] longArray)
      {
      int arrayBoundary = longArray.length * 8;

      byte [] convertedBytes = new byte[arrayBoundary];
      int byteIndex = 0;
      for (int i = 0; i < longArray.length; ++i)
      {
      convertedBytes[byteIndex++] =
      (byte) ((longArray & 0xff00000000000000L) >>> 56);
      convertedBytes[byteIndex++] =
      (byte) ((longArray
      & 0x00ff000000000000L) >>> 48);
      convertedBytes[byteIndex++] =
      (byte) ((longArray & 0x0000ff0000000000L) >>> 40);
      convertedBytes[byteIndex++] =
      (byte) ((longArray
      & 0x000000ff00000000L) >>> 32);
      convertedBytes[byteIndex++] =
      (byte) ((longArray & 0x00000000ff000000L) >>> 24);
      convertedBytes[byteIndex++] =
      (byte) ((longArray
      & 0x0000000000ff0000L) >>> 16); // the upper bits are truncated at cast
      convertedBytes[byteIndex++] =
      (byte) ((longArray & 0x000000000000ff00L) >>> 8); // idem
      convertedBytes[byteIndex++] =
      (byte) ((longArray
      & 0x00000000000000ffL)); //idem
      }
      this.data = convertedBytes;
      }

      /**
      * String Constructor
      *
      * @param initString String
      */
      public VOBlob(String initString)
      {
      byte [] convertedBytes = initString.getBytes();
      this.data = convertedBytes;
      }

      /**
      * char array Constructor
      *
      * @param charArray char array
      */
      public VOBlob(char[] charArray)
      {
      String testString = new String(charArray);
      byte [] convertedBytes = testString.getBytes();
      this.data = convertedBytes;
      }

      /**
      * com.synapps.j2eeutility.valueobjectbase.IVOBlob implementation
      *
      */
      public short[] getShortArray() {
      try
      {
      if (this.length() > 0)
      {
      int arrayBoundary = (int)this.length() / 2;
      short[] shortArray = new short[arrayBoundary];
      int byteIndex = 0;
      for (int i = 0; i < arrayBoundary; ++i)
      {
      shortArray =
      (short)((this.data[byteIndex++] & 0xFF) << 8 |
      (this.data[byteIndex++] & 0xFF));
      }
      return shortArray;
      }
      }
      catch (Exception e)
      {
      String logMessage = null;
      logMessage = "VOBlob: getShortArray() failed.";

      log.error(logMessage,e);
      }
      return null;
      }

      /**
      * com.synapps.j2eeutility.valueobjectbase.IVOBlob implementation
      *
      */
      public int[] getIntArray() {
      try
      {
      if (this.length() > 0)
      {
      int arrayBoundary = (int)this.length() / 4;
      int[] intArray = new int[arrayBoundary];
      int byteIndex = 0;
      for (int i = 0; i < arrayBoundary; ++i)
      {
      intArray
      = (this.data[byteIndex++] & 0xFF) << 24 |
      (this.data[byteIndex++] & 0xFF) << 16 |
      (this.data[byteIndex++] & 0xFF) << 8 |
      (this.data[byteIndex++] & 0xFF);
      }
      return intArray;
      }
      }
      catch (Exception e)
      {
      String logMessage = null;
      logMessage = "VOBlob: getIntArray() failed.";

      log.error(logMessage,e);

      }
      return null;
      }

      /**
      * com.synapps.j2eeutility.valueobjectbase.IVOBlob implementation
      *
      */
      public long[] getLongArray() {
      try
      {
      if (this.length() > 0)
      {
      int arrayBoundary = (int)this.length() / 8;
      long[] longArray = new long[arrayBoundary];
      int byteIndex = 0;

      for (int i = 0; i < arrayBoundary; ++i)
      {
      byte[] test = new byte[8];
      for (int x = 0; x < 8; ++x)
      {
      test[x] = this.data[byteIndex++];
      }

      BigInteger q = new BigInteger(test);
      longArray = q.longValue();
      }
      return longArray;
      }
      }
      catch (Exception e)
      {
      String logMessage = null;
      logMessage = "VOBlob: getLongArray() failed.";

      log.error(logMessage,e);
      }
      return null;
      }

      /**
      * com.synapps.j2eeutility.valueobjectbase.IVOBlob implementation
      *
      */
      public char[] getCharArray() {
      try
      {
      if ( this.length() > 0)
      {
      String testString = new String(this.data);
      char[] charArray = testString.toCharArray();
      return charArray;
      }
      }
      catch (Exception e)
      {
      String logMessage = null;
      logMessage = "VOBlob: getCharArray() failed.";

      log.error(logMessage,e);
      }
      return null;
      }

      /**
      * com.synapps.j2eeutility.valueobjectbase.IVOBlob implementation
      *
      */
      public String getString() {
      try
      {
      if (this.length() > 0)
      {
      String testString = new String(this.data);
      return testString;
      }
      }
      catch (Exception e)
      {
      String logMessage = null;
      logMessage = "VOBlob: getString() failed.";

      log.error(logMessage,e);
      }
      return null;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public long length() throws SQLException {
      return this.data.length;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public byte[] getBytes(long pos, int length) throws SQLException {
      byte[] bytes = new byte[length];
      for (int j = (int)pos; j < length; ++j)
      {
      bytes[j] = data[j];
      }
      return bytes;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public InputStream getBinaryStream() throws SQLException {
      InputStream is = new ByteArrayInputStream(data);
      return is;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public long position(byte[] pattern, long start) throws SQLException {
      /**@todo: Implement this java.sql.Blob method*/
      throw new java.lang.UnsupportedOperationException("Method position() not yet implemented.");
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public long position(Blob pattern, long start) throws SQLException {
      /**@todo: Implement this java.sql.Blob method*/
      throw new java.lang.UnsupportedOperationException("Method position() not yet implemented.");
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public int setBytes(long pos, byte[] bytes) throws SQLException {
      int bytePosition = (int)pos;
      for (int i = 0; i < bytes.length; ++i)
      {
      data[bytePosition++] = bytes
      ;
      }
      return bytes.length;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
      int bytePosition = (int)pos;
      for ( int i = 0; i < len; ++i)
      {
      data[bytePosition++] = bytes[offset + i];
      }
      return len;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public OutputStream setBinaryStream(long pos) throws SQLException {
      OutputStream os = new ByteArrayOutputStream((int)(data.length - pos));
      return os;
      }

      /**
      * java.sql.Blob implementation
      *
      */
      public void truncate(long len) throws SQLException {
      byte[] copyData = new byte[(int)len];
      for (int i = 0; i < len; ++i)
      {
      copyData = data;
      }
      this.data = null;
      this.data = copyData;

      copyData = null;
      }
      }


      The Standard JBossCMP-JDBC Configuration mapping for oracle8 looks like this:

      < mapping>
      < java-type>java.lang.Object< /java-type>
      < jdbc-type>LONGVARBINARY< /jdbc-type>
      < sql-type>LONG RAW< /sql-type>
      < /mapping>
      < mapping>
      < java-type>com.synapps.j2eeutility.valueobjectbase.VOBlob< /java-type>
      < jdbc-type>LONGVARBINARY< /jdbc-type>
      < sql-type>LONG RAW< /sql-type>
      < /mapping>
      < mapping>
      < java-type>com.synapps.j2eeutility.valueobjectbase.VOBlob< /java-type>
      < jdbc-type>BLOB</jdbc-type >
      < sql-type>BLOB</sql-type >
      < !--
      | Change this from BLOB to RAW(n) if you know your
      | serialized object will be <= n bytes and n <= 2000
      -- >
      < /mapping>

      Is the mapping wrong or is there another problem?