Re: Blobs

Armin Waibel <[email protected]> Tue, 16 Sep 2008 18:15:03 +0200
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi John,

the LOB-support of OJB 1.0.4 is very rudimentary (AFAIK OJB always 
expects that LOB's are byte[] or String fields on java object level).

The upcoming OJB 1.0.5 have more experienced LOB-support (don't remind 
me that I announced the release long ago ;-)).
I recommend to give OJB 1.0.5RC1 a try (mysql blobs are supported):
http://www.mail-archive.com/ojb-user%40db.apache.org/msg16078.html
In the included documentation you can find a new howto about LOB's.

regards,
Armin

johne wrote:
> Been doing a lot of development lately implementing our document repository. 
> Specifics include OJB 1.0.4 and MySql 5.0 with a fairly recent driver.
> 
> We were using LONGVARCHAR to represent long textual information, but was
> hoping to make it a bit more generic by changing over to using a BLOB.
> 
> Our mapping is:
> <class-descriptor class="com.comp.prod.model.document.DocumentContentVO"
> 	table="doc_content">
> 	<object-cache
> 		class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
> 		<attribute attribute-name="timeout" attribute-value="3600" />
> 	</object-cache>
> 	<field-descriptor name="docId" column="doc_id"
> 		jdbc-type="BIGINT" primarykey="true" />
> 	<field-descriptor name="content" column="content"
> 		jdbc-type="BLOB" />
> </class-descriptor>
> 
> Basically our DocumentContentVO contains just the two attributes:
> 
>     public Long docId;
>     public java.sql.Blob content;
> 
> With the appropriate getters and setters.  The MySql database has a nullable
> content column of type blob.
> 
> We were going to use javax.sql.rowset.serial.SerialBlob to add Blobs back
> into the database, but it never gets this far.  It throws an exception when
> it attempts to use our mapping to this object above in an initial query.
> 
> We get the following error:
> 
> Exception: IllegalAccess error setting field:content in
> object:com.comp.prod.model.document.DocumentContentVO host=0:0:0:0:0:0:0:1:
> 
> org.apache.ojb.broker.metadata.MetadataException: IllegalAccess error
> setting field:content in
> object:com.comp.prod.model.document.DocumentContentVO
>         at
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectImpl.setValueFor(Unknown
> Source)
>         at
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectImpl.set(Unknown
> Source)
>         at
> org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildOrRefreshObject(Unknown
> Source)
>         at
> org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectFrom(Unknown
> Source)
>         at
> org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown
> Source)
>         at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source)
>         at
> org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown
> Source)
>         at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown
> Source)
> Caused by: java.lang.IllegalArgumentException: Can not set java.sql.Blob
> field com.comp.prod.model.document.DocumentContentVO.content to [B
>         at
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
>         at
> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
>         at
> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
>         at java.lang.reflect.Field.set(Field.java:657)
>         ... 79 more
> 
> Any ideas?
> 
> Thanks as usual.
> 
> John
> 
> 
> 
> 
> 
> -----
> JohnE
> 
> http://www.jobbank.com jobbank.com