-->
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.  [ 11 posts ] 
Author Message
 Post subject: How to fetch from DB only few attributes instead all
PostPosted: Sat Dec 18, 2004 4:11 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 6:43 am
Posts: 35
Hibernate version:
2.1.6
Database

Hi,
We process thousands of rows and we notice that execution time is fast but fetch time is rather long.
It is possible because our biggest object has 70 attributes, but for part of processing we need to read/update (there are no inserts) only let say 30-40% of attributes. Simply we can only fetch necessary data, that should minimize time of fetch (=sending to client + time of mapping to Java fields).

Is it possible to disable reading from table selected fields ?

Regards
Michal Szymanski
http://michal.szymanski.free.fr


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 18, 2004 5:48 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Create a constructor on the object with lots of fields that only has the fields you want. Then run a query like:

Code:
select new WideObject( obj.firstField, obj.secondField ... obj.lastField ) from WideObject obj


Downside is that objects created in this fashion won't be in the session cache so if you change them you'll have to use the explicit session.update( wideObject ) to commit changes.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 18, 2004 5:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
in hibernate 3 you have lazy at property level.
you're the first guy i see that can need it ;)

You should check
http://www.hibernate.org/41.html
that's what you need

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 6:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
also look at dynamic-insert,dynamic-update to maybe improve the time used to update/insert time (test its actual effect since it differ on databases)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 7:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Finally, check the "lightweight class" pattern on the Wiki.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
gavin - did you try to follow the link anthony showed ? :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 7:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
oh. no. I thought Anthony was linking to something about <property lazy="true"/> ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 8:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
We should probably try to copy and paste the URL of the "Link" link in the topright corner of the page when posting Wiki URLs - e.g. http://www.hibernate.org/Documentation/LightweightClass for this one. I always forget about it, too, however.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 11:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
nice - actually didn't know it existed ;)

thank for that tip ...weird that the wiki internally uses the numbered nonhuman readable ones ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 4:39 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 6:43 am
Posts: 35
Thank you for advice. First we have to confirm that "fetch time" is a issue in production environment. If yes we will use your advice. As I've promised at the and of the our project I will write short article about processing huge numbers of data using Hibernate ,- we have many advices that can be helpful for others. Currently our system produce about 1mln rows per day.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The "numeric" URLs in the wiki are more stable than the human readable links (which can change if you edit the title of the page).


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