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: Improving performance using Hibernate with a legacy database
PostPosted: Thu Aug 03, 2006 12:51 pm 
Newbie

Joined: Thu Aug 03, 2006 11:48 am
Posts: 2
Location: Columbus, OH
Hello All,

You will probably tell me to CTFI on this one, but I have been searching for a little over an hour and can find no best practices, standard solutions, or examples regarding my problem.

I am using Hibernate with a legacy database system and I have no control over the database structure. I have Hibernate configured properly and running correctly. However, I am running into a quite a large performance issue.

The database table I am trying to access contains 30 some char or varchar fields and a BLOB. The BLOB field is usually 4MB in size. Not the smartest database design in the world, I know, but that's a different issue for a different forum. The POJO that I created for Hibernate looks something like this:

Code:
public class MyObject {

    string field1;
    string field2;
    // etc etc

   byte[] data;

    // cunstructors, getters and setters

}


At any point in time, there can be hundreds of thousands of records in this particular database table. I am creating a web interface to allow a user to "preview" the rows in the table. The user will provide some initial search criteria to somewhat limit the number of records returned. Any way you look at it, there will be MANY records returned, however. Since there is no reason to display the binary data in the byte array in the web interface, and because fetching 4MB x 6000 records would be an obvious performance no-no, I would like to defer the fetching of the data in the BLOB field in the database until a later time (ie. the user clicks the record).

If I controlled all aspects of this application, I would most likely create two database tables/POJO mapping classes, called something like MyObjectData and MyObject and simply maintain a one-to-one relationship between the two. As I have mentioned, I have no control over the strcuture of the database, so this is an impossibility.

Aside from this solution, what else can I try?

Thanks so much for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 03, 2006 5:06 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
set lazy="true" on the class.

when you load MyObject, it will only load the primary key and any additional fields you specifically load. For example

Code:
openSession();
MyObject mo = session.load(pk);
mo.getField1();
mo.getField2();
mo.getField3();
session.close();


will load the mo object with the pk, Field1, Field2, Field3 set. The giant 4 meg thing will not be loaded. Only a proxy set in its place

then, when you need to get the 4 meg thingy for a more detailed view, just load it in another session.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 9:01 am 
Newbie

Joined: Thu Aug 03, 2006 11:48 am
Posts: 2
Location: Columbus, OH
Awesome! Thanks a lot!


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.