It's pretty simple unless you're using the Oracle thin driver (more on this in a 
second).  In the mapping for the column just declare the column to be of type 'BLOB' 
and optionally specify a field conversion:

      <field-descriptor
         name="blobValue"
         column="my_blob_column"
         jdbc-type="BLOB"
         conversion="com.whisperwire.platform.db.ojb.ByteArray2BlobFieldConversion"
      />

If you don't specify a field conversion OJB will use the default field conversion 
which is going to expect the class' field to be of type java.sql.Blob.  This works 
okay under JDBC 3.0 where the Blob interface is modifiable but requires db specific 
code for JDBC 2.0 (i.e. jdk 1.3.x) because you have to be able to create a new 
instance of the Blob and each JDCB driver has their own implementation.  We use custom 
field conversions to convert the Blob back and forth to what we want, the simplest 
being just a byte[]:

public class ByteArray2BlobFieldConversion implements FieldConversion {

        /**
         * @see 
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
         */
        public Object javaToSql(Object source) throws ConversionException {
                // source should already be byte[]
                return source;
        }

        /**
         * @see 
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
         */
        public Object sqlToJava(Object source) throws ConversionException {
                if (source == null) {
                        return null;
                }
                try {
                        if (source instanceof Blob) {
                                Blob b = (Blob) source;
                                byte[] bytes = b.getBytes(1, (int) b.length());
                                return bytes;
                        } else {
                                return source;
                        }
                } catch(SQLException se) {                      
                        throw new WrappedRuntimeException(se);
                } 
        }
}

For certain versions of the Oracle thin driver there is a hard limitation (really 
annoying Oracle bug) of 4k worth of data that can be updated through the Blob 
interface (no corresponding limitation on reading a Blob value).  This is definitely 
present in the Oracle 8.x thin drivers but I believe it may be fixed in the Oracle 9.x 
thin drivers.  If you have this situation let me know and I'll give you more details 
on what you have to do to workaround this.

-----Original Message-----
From: Carlos Henrique Leclerc De Oliveira [mailto:[EMAIL PROTECTED]
Sent: Friday, September 19, 2003 7:58 AM
To: 'OJB Users List'
Subject: RE: OJB + Oracle BLOB


Thanks Max, but this documentation
didn´t was finished yet...and the
part that describe how to
use, is to be written yet.

Did you already use Oracle BLOB´s
with OJB?

regards,
Carlos

-----Original Message-----
From: Geigl Maximilian, R235 [mailto:[EMAIL PROTECTED]
Sent: sexta-feira, 19 de setembro de 2003 04:04
To: OJB Users List
Subject: AW: OJB + Oracle BLOB


Hi,

this should help:

http://db.apache.org/ojb/howto-use-lobs.html

Regards
Max

> -----Ursprüngliche Nachricht-----
> Von: Carlos Henrique Leclerc De Oliveira [mailto:[EMAIL PROTECTED]
> Gesendet: Donnerstag, 18. September 2003 23:03
> An: 'OJB Users List'
> Betreff: OJB + Oracle BLOB
> 
> 
> Hi all,
> 
> Could you tell me how oracle Blobs 
> are loaded and stored, using OJB, please?
> 
> There are not documentation...
> 
> regards,
> Carlos
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: quinta-feira, 18 de setembro de 2003 16:10
> To: [EMAIL PROTECTED]
> Subject: Xdoclet and transient fields.
> 
> 
> 
> 
> 
> 
> Hello All,
> Why does XDoclet ignore transient references? I have a 
> transient collection
> defined that I want to store and I use transient for serialization
> purposes.
> When I use transient keyword xdoclet ignores collection 
> completely, but
> when i remove a transient keyword it works fine.
> Any thoughts?
> 
> Thanks,
> Roman
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to