2

My project parse XML file from dblp , it about 1GB to save in ORM database, so I use SAXP for reading information like (paper'author, paper'infomation ......).

The function reading is OK but when I using hibernate to save information to database it have error: "java.lang.OutOfMemoryError: Java heap space "

BenMorel
  • 34,448
  • 50
  • 182
  • 322
tiendv
  • 2,307
  • 7
  • 23
  • 34
  • I have been edit mapping – tiendv Nov 29 '11 at 03:49
  • Post the actual mappings. And the full stack trace of the exception. How can anyone help you if you don't even show the error? – Strelok Nov 29 '11 at 03:51
  • sorry for absent information of my previous post, i just added now – tiendv Nov 29 '11 at 04:10
  • So the exception happens inside AuthorBO constructor, that's progress. What are you doing in that constructor? – Strelok Nov 29 '11 at 04:28
  • When i brown in database it insert, but it' run about 2 minute throw out of memory (i have been insert class Author bo) – tiendv Nov 29 '11 at 04:39
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5427/discussion-between-tiendv-and-strelok) – tiendv Nov 29 '11 at 04:44

2 Answers2

2

you should use stateless sessions for such large data sets. please read about it at jboss website

aishwarya
  • 1,970
  • 1
  • 14
  • 22
0

From the stack trace , it seems that the java.lang.OutOfMemoryError is not due to Hibernate because it happens when the SessionFactory is built.

I think it is due to the big size XML you are parsing . You can verify it by parsing a smaller XML. If it can be saved , you can isolate the problem is not caused by Hibernate .

You can increase the maximum heap size of your Vm by using the -Xmx parameter , for example:

java -Xmx2048m 
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • Thanks your reply . When i run a xml file 1MB it run OK, but when i run xml file 10MB it throw memory, so without hava al big Ram ~~!, any idea for this situation? Thanks – tiendv Nov 29 '11 at 06:02
  • Did you try to increase the maximum heap size of your Vm by `-Xmx` parameter? – Ken Chan Nov 29 '11 at 06:07
  • yes , i did , but it throw same error I have try your suggest another post but ....... same eror protected void commitAndClose() { if (session != null) { for(int i=0;i<1000;i++) { if ( i % 50 == 0 ) { //50, same as the JDBC batch size //flush a batch of inserts and release memory: session.flush(); session.clear(); } } session.getTransaction().commit(); if (session.isOpen()) { session.close(); } } – tiendv Nov 29 '11 at 06:09
  • I do this solution to but it' can't fix proplem http://stackoverflow.com/questions/6687422/hibernate-batch-size-confusion – tiendv Nov 29 '11 at 09:06