You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Björn Voigt <bv...@hs-harz.de> on 2003/09/17 18:38:30 UTC

Problem with byte[] to bytea mapping

Hi Obj_friends,

I have problems with mapping of an image to an postgresql database.
A byte[] attribute holds my image data. The column type is bytea.
The mapping look like:

<class-descriptor class="de.mobiharz.model.media.Image" table="images">
...
	<field-descriptor
		id="3"
		name="image_data"
		column="imag_data"
		jdbc-type="BINARY"/>
...
</class-descriptor>

If I store the object to database and get it back, the length of
the byte[] is bigger than the original length.


It would be  nice , if somebody can help

Björn



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem with byte[] to bytea mapping

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi,

in a previous mail you said
> Castor allows u to map an byte[] to BLOB (bytea in postgres).
in OJB if the standard mapping does not fulfill your
expectations it is possible to use OJB's FieldConversion
feature.
See http://db.apache.org/ojb/repository.html#field-descriptor
OJB was shipped with some standard FieldConversion classes.
Maybe this will help you.

regards,
Armin

----- Original Message -----
From: "Björn Voigt" <bv...@hs-harz.de>
To: <oj...@db.apache.org>
Sent: Thursday, September 18, 2003 12:01 PM
Subject: Re: Problem with byte[] to bytea mapping


> Christian Pesch schrieb:
> > Björn Voigt wrote:
> >
> >> If I store the object to database and get it back, the length of
> >> the byte[] is bigger than the original length.
> >
> >
> > Did you compare the original value and the written one?
> > May be that gives a hint.
>
> In my last message I wrote some wrong,
>
> I tested the storing again with castor and ojb.
>
> I made 4 tests.
>
> 1. Store with Castor / Load with Castor successful
> 2. Store with Ojb    / Load with Ojb    non successful
> 3. Store with Castor / Load with Ojb    non successful
> 4. Store with Ojb    / Load with Castor non successful
>
> select length(image_column) from images has in all cases
> the same value. The data of all 4 rows looks same.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem with byte[] to bytea mapping

Posted by Björn Voigt <bv...@hs-harz.de>.
Christian Pesch schrieb:
> Björn Voigt wrote:
> 
>> If I store the object to database and get it back, the length of
>> the byte[] is bigger than the original length.
> 
> 
> Did you compare the original value and the written one?
> May be that gives a hint.

In my last message I wrote some wrong,

I tested the storing again with castor and ojb.

I made 4 tests.

1. Store with Castor / Load with Castor successful
2. Store with Ojb    / Load with Ojb    non successful
3. Store with Castor / Load with Ojb    non successful
4. Store with Ojb    / Load with Castor non successful

select length(image_column) from images has in all cases
the same value. The data of all 4 rows looks same.



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem with byte[] to bytea mapping

Posted by Björn Voigt <bv...@hs-harz.de>.
Christian Pesch schrieb:
> Björn Voigt wrote:
> 
>> If I store the object to database and get it back, the length of
>> the byte[] is bigger than the original length.
> 
> 
> Did you compare the original value and the written one?
> May be that gives a hint.

Hi Christian,

here are the sample files I use,
test1.jpg was written to db using ojb

test2.jpg ist the result.

The length of the image is bigger then the original length,
there goes something wrong during the insert. I used castor
before with the same class and table, but there goes nothing
wrong.

Castor allows u to map an byte[] to BLOB (bytea in postgres).
I tried BINARY/VARBINARY/LONGVARBINARY in ojb, but I got this
wrong byte[] back.


Re: Problem with byte[] to bytea mapping

Posted by Christian Pesch <ch...@coremedia.com>.
Björn Voigt wrote:

> If I store the object to database and get it back, the length of
> the byte[] is bigger than the original length.

Did you compare the original value and the written one?
May be that gives a hint.


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org