Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Heap Space

 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, seriously, I don't know where to put this topic so go ahead remove it if it's in the wrong place.

I have been doing this project with Struts2-jQuery and Hibernate. I used Data Access Objects to get the pojo classes of the entities in the table. I'm accessing now one of the DAOs putting it on a grid and then I get a heap space error just like this..



..when the only code I'm trying to run is this..



The original code from the DAO is this..



So, how do I fix this one? I tried using another computer and run the coded there and it went just fine until I think I overloaded the memory yet again and it also went beserk and had the heap space error. Please help me out. I have a deadline on sunday and I'm really worn out because of this.. Thank you.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Monica,

Are you sure your query is ok ? your obviously fetching way to much objects.
Can't you specify it more to make the resultset smaller ?

What are you doing with the objects ? If your are for instance just showing the name of the loan, it is a little overkill to fetch te complete object.

You could consider using paging on your results :paging in hibernate
 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, on the other computer, the one that went well and then crashed, it only had one Loan on it. On mine it had, I think, about seven Loans on it. And it's actually filtered because I only get the ones that are of the "Pending" status. Also, I have tried loading LoanApplications. It goes well when I load that grid and that has about 600 applications in there and a lot more additions to it like its Appraisals, etc. So I'm quite perplexed as to what it may have caused the heap space. I already tried deleting the cache, but it seems that it's not working.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure the out of memory is caused by Hibernate ?
I don't see no hibernate in your stacktrace.

 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm isnt this your problem ? : click me
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned by Mark, the most likely cause is that large amount of data/rows is being loaded.
You need to look at the number of rows being returned. In case it is a normal scenario to get these many records you can look at option of increasing the heap size. Can be done by -Xmx.
You can also look at associations, are these lazily loaded?
You can also look at the heap dump to see the type of objects that are there in the heap. This will give you pointers on what objects are being kept in the heap. You need set JVM option which will create a heap dump when Out of Memory exception is encountered.
 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another grid that uses Loanapplications and that one have more records than the Loans. Loanapplications work well but the Loans doesn't. I've seen that Javanus post although I don't have an @OneToMany tag on my pojo class, rather a tag on the hbm.xml so I don't really know how to use that one. The other grids using the LoansDAO and Loans object, after having my heap space, also had heap space on them. I'm guessing it's because of the Loans.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well its probably not the amount of records, I think you would have this with one record also. It is probably a misconfiguration in your hbm.xml
file.
Can you post that one (or at least the relevant part of it with the Loan entity and its children)

 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
about the javanus link: he had links in 2 directions (so a one to many in one class and a many to one in the second back to the first class) and it worked after removing one part (he had a loop in his references I think)

I had a look at the xml, but frankly I'm not used to reading xml , nowadays we all work with annotations.

I would try to put some pieces of the xml in comment and try to get it running. That way you can try to localize which part is causing the problem, that way you can dig further on that. (Another is creating a heap dump and analyzing that one as already suggested)

I'm also missing something about lazy loading in your xml file. Fetching Strategies

You don't want to load the complete object graph with all its children if all you need to do is show the name in the grid...

 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding lazy="true" at your set collections.
 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I have resolved the problem already by removing something off of the Loans class. Thanks for your help everyone.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you remove?
 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some iteration for finding its Voucher object. I don't know why that caused the heap space when I had that one before. I have another problem here... http://www.coderanch.com/t/542624/java/java/Struts-Null-Pointer-Exception-at
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it might be running fine earlier as you might be using different database with different volumes/data.
 
Monica Salvador
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really. I haven't changed a thing on the database. And as I've said before, I used another computer and it went well until it crashed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic