-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: how to handle large table in Hibernate?
PostPosted: Sat May 08, 2004 3:19 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi,
when i insert or retrieve some record which is very large ,the exception will be generated java.lang.OutOfMemoryError,why?the two table is parent/child relationship,and i set the lazy=false
the code is following:
JournalEntryDAO dao = new JournalEntryDAO(
"companyb");
String batchNo = "batchNo";
JournalBatch journalBatch = dao.retrieve(batchNo);
if (journalBatch != null) {
System.out.println(journalBatch.getBatchNo());
dao.deleteBatch(batchNo);
}
journalBatch = new JournalBatch();
journalBatch.setBatchNo(batchNo);
Collection journalEntries = new ArrayList();
for(int i=0;i<50000;i++)
{
String referenceNo1 = "referenceNo"+i;
JournalEntry journalEntry1 = new JournalEntry();
journalEntry1.setReferenceNo(referenceNo1);
journalEntry1.setBatchNo(journalBatch);
journalEntries.add(journalEntry1);
}

journalBatch.setJournalEntries(journalEntries);
dao.create(journalBatch);
JournalBatch batchLoad=dao.retrieve(batchNo);
System.out.println(((JournalEntry)batchLoad.getJournalEntries().toArray()[9998]).getReferenceNo());
the hbm file is following:the parent
<bag name="journalEntries" inverse="true" cascade="all">
<key>
<column name="batchNo"/>
</key>
<one-to-many class="JournalEntry"/>
</bag>
the child<many-to-one
name="batchNo"
column="batchNo"
class="JournalBatch"
not-null="true"
>
<column name="batchNo" />
</many-to-one>
Thanks in advance for all the help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 4:33 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"System.out.println(((JournalEntry)batchLoad.getJournalEntries().toArray()[9998]).getReferenceNo());"
Are you sure this is not the cause of OutOfMemoryError ?
Why to you load database to memory if you need just "referenceNo" at 9998 ?


Top
 Profile  
 
 Post subject: Thanks baliukas
PostPosted: Sat May 08, 2004 4:41 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
Thanks for your reply.
i am sure it is not caused by the the sentence,for when i comment it ,the same to uncomment.
this is just test code,for in production,the system will need such a large data insert and retrieve.
what is the reason of this? is it caused by the lazy=false?why?can anybody help me?Thanks.



baliukas wrote:
"System.out.println(((JournalEntry)batchLoad.getJournalEntries().toArray()[9998]).getReferenceNo());"
Are you sure this is not the cause of OutOfMemoryError ?
Why to you load database to memory if you need just "referenceNo" at 9998 ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 6:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
If you do not need data in memory then load it "lazy".


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 8:35 pm 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi,baliukas
but i need it,this will cause OutOfMemory exception?can i make it work?
can u help me?
Thanks for your kindness.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 09, 2004 9:54 pm 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
can anyone help me?[b][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the size of every single object (and linked one wo lazy) * 50000, how much do you have ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:08 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi,emmanuel
thanks for your reply.
but i don't konw how to estimate the size of the object,may u tell me?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:19 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
and how do u think about this situation? what caused this?
thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:33 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
there is no "standard way" to handle large table with hibernate ?
such as retrieve 100k rows records from one table.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:39 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why would you load your database into memory? Use a stored procedure.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:45 am 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi,christian
thanks for your reply.
what is the standard way of hibernate to deal with this situation?
i mean ,can i use hibernate to deal with the situation?
if not,what is the better way?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You should not load your database into memory and therefore, not use Hibernate to load and save millions of objects. You implement a Stored Procedure in the database and call it, using straight SQL and JDBC.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 8:53 pm 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi ,christian
Thanks for your help.
YangLei


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 10:11 pm 
Newbie

Joined: Thu Apr 08, 2004 8:23 am
Posts: 16
Location: beijing/china
hi ,christian
can u tell me what is the max rows Hibernate allowed?
thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.