aspose file tools*
The moose likes Object Relational Mapping and the fly likes java.lang.outofmemoryerror: java heap space hibernate batch insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "java.lang.outofmemoryerror: java heap space hibernate batch insert" Watch "java.lang.outofmemoryerror: java heap space hibernate batch insert" New topic
Author

java.lang.outofmemoryerror: java heap space hibernate batch insert

kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
Hi,
I am trying to insert bulk records into a table, the following is code in my dao. I am using spring and hibernate

for(int i=0;i<allImportClients.size();i++){

ImportClients importClient = (ImportClients)allImportClients.get(i);
getHibernateTemplate().saveOrUpdate(importClient);
if ( i % 10 == 0 ) {
getHibernateTemplate().flush();
getHibernateTemplate().clear();
}
}

and my cfg.xml file has

<property name="hibernate.jdbc.batch_size">10</property>
<property name="hibernate.cache.use_second_level_cache">false</property>

This works fine when i am uploading 1200 records manually.
But when i try with loadrunner by creating 4 vusers who cocurrently insert 1200 records each, then it is throwing exception as

java.lang.outofmemoryerror: java heap space

Please, help me.
Thanks in advance
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

This is pretty much "what you see is what you get."

You're out of memory, either on your JVM, your computer, or both.

Is there any reason to believe it is something other than that? Let us know what you're thinking.

-Cameron McKenzie
kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
thanks for your reply.

I agree that the problem is with memory
But i wanted to know what I need to do to solve this........

Any suggestions will be really useful to me.

Thanks a lot in advance.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Well, the first things that come to mind are potentially increasing the Java heap size, which can be done with JVM switches.

-Xmsinitial java heap size
-Xmxmaximum java heap size

You might also want to increase the amount of physical memory on the machine.

Maybe even distributing the load across several JVMs might help address the problems.

Nothing magical, unfortunately.

Good luck!

-Cameron McKenzie
kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.
Ramesh Srinivasan
Ranch Hand

Joined: Aug 17, 2008
Posts: 35
Originally posted by kkalyan kkumar:
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.


Hi Kalyan,

I believe you have an INI file at your maven path. INI file you would able to see the arguments as you mentioned above. Change your setting there. It will work.

~Ramesh.


SCJP 5.0 93%<br /> <br />"We are what we repeatedly do , then excellence is not an action it is an Habit" Aristotle
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Originally posted by kkalyan kkumar:
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.


Um, Maven is your build technology, not running Java.

Unless it is while you are building that you do the bulk insert. And maybe even then you still want your "java" memory increase, so you would have to look in your pom.xml for the line that runs "java" and add it there. That is if it is when you build that it does the inserts.

If it is in your application, then you need to add that option to the line that calls "java" when you start up your application.

However, are you sure the code inside this if statement is ever called?

if ( i % 10 == 0 ) {
getHibernateTemplate().flush();
getHibernateTemplate().clear();
}

Because that should evict those objects and you shouldn't have a memory problem with Hibernate.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
Hey,

Thanks for really useful help
Ya, the if condition is executed and i am not getting the out of memory exception when i manually do bulk insert.

As posted in my first comment, the problem comes when i do bulk insert with
loadrunner........

anyway, now i am looking into loadrunner.

thanks a lot for the help
kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
the bulk insert goes in my application when user triggers it by clicking an uploading a file with bulk data.

You said,

........
you need to add that option to the line that calls "java" when you start up your application.
.........

Hey Mark Spritzler, out of interest i am asking,
what does the above line means.........sorry, i did not understand it exactly.

can you please give some more pointers that helps me to understand it.

Thanks in advance
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

OK, click, from where a Swing application, a website, or from some other app that calls out to java?

In a swing app, whatever starts your main class. From a website, probably be your server like when you start Tomcat or some app server. From some other app that calls out to java, then in that call. Wherever java is being called that loads your classes.

Mark
kkalyan kkumar
Greenhorn

Joined: Jul 23, 2008
Posts: 12
Thanks a lot for the input
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.outofmemoryerror: java heap space hibernate batch insert