-->
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.  [ 7 posts ] 
Author Message
 Post subject: Lazy Loading: is the right solution for my purpose??
PostPosted: Thu May 24, 2007 5:55 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
Hi,
I'm devloping an application that manages files upload and download.
The file itself can be quite large, so is not so usefull laod the file-data everytime in the java object if i have only to know, for exmaple, the filename.

I think something like lazy loading can be really usefull, but for what i've read it's used only with associations and not with internal attributes.

Is there someone that have a good hint??


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 10:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Such question should go to the regular user forum
Use a blob (lazy as per the spec)
or http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#performance-fetching-lazyproperties

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 8:16 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
Sorry, i've started thinking about an annotation that could tell hibernate to load the field on-demand. ( like @LazyToOne).
Then i tought to ask something more general cause i've not really get clearly how this annotation works.

I'm already using a java.sql.Blob class for that field. Does hibernate load the field donly when accessed??

I will read the link that you have passed to me.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 8:35 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
I've used the java.SQL.Blob type, but my test shows that the filed is laoded without using a lazy policy.
Is there an annotation that specify that a field, not an association, as to be loaded only on demand??

Thanks for any reply

P.S.: I explain shortly the test.
I have loaded in the DB a big file ( 148MB ) and when i try to list all the files loaded showing only the filename and the content-type i get this exception:

Code:
java.lang.OutOfMemoryError
MESSAGE: Java heap space


I think this shows that the field File of the entity is loaded eagerly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The Blob lazy loading should be done by your driver. So it seems you have a flawed driver.
If you are using MySQl, they don't support lazy blobs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 3:20 am 
Newbie

Joined: Wed May 23, 2007 10:07 am
Posts: 12
Location: Italy
You guessed right... I'm using MySQL.
So the only solution is to have two different entity, one with the Blob field and one without, isn't it?

Maybe i ask in another forum... I'm going OT.

Thanks anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can use such a pattern
http://www.hibernate.org/41.html

Note if you enhance the class, and use @Lob @Basic(fetch=LAZY) the blob should not be loaded. I'm not 100% sure but I guess so

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.