-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate transaction with large data amount
PostPosted: Mon Jan 12, 2009 6:04 am 
Newbie

Joined: Tue Mar 22, 2005 10:44 am
Posts: 8
Hibernate version: 3.1

I would like to perform a transaction with large data amount using hibernate.

I get a "java.lang.OutOfMemoryError: Java heap space" error,
because Hibernate uses RAM (Hibernate Session) to store all data for actual transaction.

The database Oracle would use his rollback segment on disk which can be very large.

Can I call hibernate to use this oracle rollback segment instead of his Hibernate Session (RAM) to store data for transaction ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 6:14 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
u have to use batch processing for large data access from hibernate.

First set the jdbc.batch_size property to any number b/w 10 to 50 in hibernate.cfg.xml file.

if u r saving & update more no. of objects into DB. then check the loop index for batch size if it reaches that flush() and clear() the session.

Actually batch processing used for large number of objects accessing. for eg., if we r going to save 5000 users data without batch in middle of 1000 or some object the JVM show error Heap Memory Out exception.

for eg., how to use batch process for saving users object .

set jdbc.batch_size=30 in hibernate.cfg.xml file


for(int i=0;i<users.length;i++)
{
Users u =new Users();
u.setId(i);
....
if(i%30==0){
session.flush();
session.clear();
}
session.save(u); // session.update(u);
}

In this way we will deal with batch processing. it same procedure used in update also.

For more info.,
www.hibernate.org/hib_docs/reference/en/html/batch.html

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 9:00 am 
Newbie

Joined: Tue Mar 22, 2005 10:44 am
Posts: 8
Thank you very much for your very fast reply !!

Looking at your example my question is:
How can I save all the 5000 users in ONE transaction ?
If I set batch size to 30, than I only save 30 users in one transaction
and open a new one.
That is not exactly what I want to do.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 1:46 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
flush() doesn't commit the data in the database. If the save() or update() was outside the for loop, the operation is still atomic.

Linhib.


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