You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lon Varscsak <lo...@gmail.com> on 2019/10/02 23:55:44 UTC

Best Practice for blobs

Hey all,

I have a blob column in an entity, but I don't want to always actually load
the blob, just on demand (but I still want to be able to see the other
attributes in the entity).  Any best practice here to have the blob be lazy?

Thanks,

Lon

Re: Best Practice for blobs

Posted by Lon Varscsak <lo...@gmail.com>.
Okay, thanks all...this is pretty much what I thought but wanted to make
sure I wasn't missing something.

On Thu, Oct 3, 2019 at 5:28 AM Michael Gentry <bl...@gmail.com> wrote:

> I've always used a secondary table (1:1 relationship) which contained just
> the blob data.  The parent table would have the metadata for the blob, and
> possibly other data as required.  That way you can fetch in the name, file
> size, type, etc without fetching in the blob until needed.
>
>
> On Wed, Oct 2, 2019 at 8:02 PM Lon Varscsak <lo...@gmail.com>
> wrote:
>
> > Hey all,
> >
> > I have a blob column in an entity, but I don't want to always actually
> load
> > the blob, just on demand (but I still want to be able to see the other
> > attributes in the entity).  Any best practice here to have the blob be
> > lazy?
> >
> > Thanks,
> >
> > Lon
> >
>

Re: Best Practice for blobs

Posted by Amedeo Mantica <am...@me.com.INVALID>.
+1

> On 3 Oct 2019, at 14:27, Michael Gentry <bl...@gmail.com> wrote:
> 
> I've always used a secondary table (1:1 relationship) which contained just
> the blob data.  The parent table would have the metadata for the blob, and
> possibly other data as required.  That way you can fetch in the name, file
> size, type, etc without fetching in the blob until needed.
> 
> 
> On Wed, Oct 2, 2019 at 8:02 PM Lon Varscsak <lo...@gmail.com> wrote:
> 
>> Hey all,
>> 
>> I have a blob column in an entity, but I don't want to always actually load
>> the blob, just on demand (but I still want to be able to see the other
>> attributes in the entity).  Any best practice here to have the blob be
>> lazy?
>> 
>> Thanks,
>> 
>> Lon
>> 


Re: Best Practice for blobs

Posted by Michael Gentry <bl...@gmail.com>.
I've always used a secondary table (1:1 relationship) which contained just
the blob data.  The parent table would have the metadata for the blob, and
possibly other data as required.  That way you can fetch in the name, file
size, type, etc without fetching in the blob until needed.


On Wed, Oct 2, 2019 at 8:02 PM Lon Varscsak <lo...@gmail.com> wrote:

> Hey all,
>
> I have a blob column in an entity, but I don't want to always actually load
> the blob, just on demand (but I still want to be able to see the other
> attributes in the entity).  Any best practice here to have the blob be
> lazy?
>
> Thanks,
>
> Lon
>

Re: Best Practice for blobs

Posted by Jurgen Doll <do...@xsinet.co.za>.
Hi Lon

Not sure if this is best practice but I created two Cayenne object entities 
where the first excludes the blob and the second only has the blob.

Then I either:

1. Added a relationship attribute in the first pointing to the second, based 
on a 1:1 relationship in the DbEntity.

2. Or I manually added a method to the first, to fetch the blob with 
something like:

    Cayenne.objectForPK( context, ImageBlob.class, 
Cayenne.longPKForObject( this ) );

Jurgen


-----Original Message----- 
From: Lon Varscsak
Sent: Thursday, October 3, 2019 1:55 AM
To: Apache Cayenne
Subject: Best Practice for blobs

Hey all,

I have a blob column in an entity, but I don't want to always actually load
the blob, just on demand (but I still want to be able to see the other
attributes in the entity).  Any best practice here to have the blob be lazy?

Thanks,

Lon 


Re: Best Practice for blobs

Posted by Andrus Adamchik <an...@objectstyle.org>.
I wanted to have attributes that can be tagged as "lazily-loaded" like relationships, but that's not a feature yet. So what Ari said is the easiest solution. 

Another idea is to map the column as "java.sql.Blob", which is normally just a data locator that can stream data on demand. Though I suspect you will need to wrap both SELECT, and your Blob streaming code in the same transaction. Also the behavior of this will likely vary between DB engines. 

Disclaimer: I never tried it myself.

Andrus


> On Oct 3, 2019, at 3:43 AM, Aristedes Maniatis <ar...@maniatis.org> wrote:
> 
> My solution has been to store the blob in a separate joined table or (better) put it in external storage like S3.
> 
> Ari
> 
> On 3/10/19 9:55am, Lon Varscsak wrote:
>> Hey all,
>> 
>> I have a blob column in an entity, but I don't want to always actually load
>> the blob, just on demand (but I still want to be able to see the other
>> attributes in the entity).  Any best practice here to have the blob be lazy?
>> 
>> Thanks,
>> 
>> Lon
>> 


Re: Best Practice for blobs

Posted by Aristedes Maniatis <ar...@maniatis.org>.
My solution has been to store the blob in a separate joined table or 
(better) put it in external storage like S3.

Ari

On 3/10/19 9:55am, Lon Varscsak wrote:
> Hey all,
>
> I have a blob column in an entity, but I don't want to always actually load
> the blob, just on demand (but I still want to be able to see the other
> attributes in the entity).  Any best practice here to have the blob be lazy?
>
> Thanks,
>
> Lon
>