-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How can I prevent some columns from fetching by default?
PostPosted: Fri Sep 30, 2011 2:14 am 
Beginner
Beginner

Joined: Wed Jul 30, 2008 8:43 am
Posts: 32
Hi.

I have a blob column (byte[] field) and using Postgres. I need to avoid the fetch for this column by default and only fetch the field when I need to download the file, which is located there. How can I do this in Hibernate using annotations? I can write all columns in HQL query except for this blob and construct objects manually from fields. But this is not beautiful at all and seems more like a huck. Is there any other rapid and convenient way?

Thanks, Anton


Top
 Profile  
 
 Post subject: Re: How can I prevent some columns from fetching by default?
PostPosted: Sat Oct 01, 2011 1:25 pm 
Newbie

Joined: Sat Oct 01, 2011 1:16 pm
Posts: 1
If I understand your problem correctly, you should be able to solve this by using lazy fetching.

For example, annotate your blob property like this:

@Basic(fetch=FetchType.LAZY)
private byte[] myLargeProperty;

(@Basic can be used together with the @Lob annotation if you already use that on the property.)


In this case, the property won't be fetched automatically. When calling the getMyLargeProperty() getter, a new SELECT will be issued that retrieves the field value.

_________________
Niclas Andersson
Netlight Consulting


Top
 Profile  
 
 Post subject: Re: How can I prevent some columns from fetching by default?
PostPosted: Thu Oct 06, 2011 1:26 am 
Beginner
Beginner

Joined: Wed Jul 30, 2008 8:43 am
Posts: 32
Niclas, thanks, but this didn't help.

I have the field with following notations:
Code:
    @NotNull
    @Column(name="contentOid")
    @Basic(fetch=FetchType.LAZY)
    private byte[] content;


And use standard hql fetch:

Code:
em.createQuery("from BinaryDocument").getResultList()


This results in select for all columns, including the contentOid. Adding @Lob didn't help either...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.