-->
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.  [ 3 posts ] 
Author Message
 Post subject: OutOfMemoryError working with blobs
PostPosted: Sun Feb 14, 2010 7:34 pm 
Newbie

Joined: Sun Feb 14, 2010 7:13 pm
Posts: 6
Hi, I am experiencing out of memory errors working with some objects that contains blobs.
I think the issue comes from the hibernate caching, but I don't know how to solve them.

I have a class to represent a Journal that basically contains some information and a collection of Articles.
The article class contains some information and the full text pdf stored as a blob.

To fill in the database I have a crawler that gets the information and adds the data to the Journal class, so I have to get it from the database. To do that I use this code
Code:
Journal journal = (Journal) session.getNamedQuery(
               "findJournalByName").setParameter("journalName",
               journalName).uniqueResult();

         if (journal == null) {
            journal = new Journal(journalName);
         }

Then, after I retrieved all the information I need, I am able to persist the article object but as soon as I try to add the object to the journal I get the out of memory exception.
Code:
session.saveOrUpdate(article);
journal.addArticle(article);


The query I get is the following
Code:
Hibernate: select articles0_.JOURNALS_JournalId as JOURNALS1_1_, articles0_.articles_ArticleId as articles2_1_, article1_.ArticleId as ArticleId1_0_, article1_.articleAbstract as articleA2_1_0_, article1_.fullTextPdf as fullText3_1_0_, article1_.title as title1_0_, article1_.year as year1_0_ from JOURNALS_ARTICLES articles0_ left outer join ARTICLES article1_ on articles0_.articles_ArticleId=article1_.ArticleId where articles0_.JOURNALS_JournalId=?

and I get this exception
Code:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
   at com.mysql.jdbc.Blob.getBytes(Blob.java:149)
   at org.hibernate.type.ByteArrayBlobType.get(ByteArrayBlobType.java:90)
   at org.hibernate.type.AbstractLobType.nullSafeGet(AbstractLobType.java:46)
   at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
   at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2114)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
   at org.hibernate.loader.Loader.getRow(Loader.java:1230)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
   at org.hibernate.loader.Loader.doQuery(Loader.java:724)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:2019)
   at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
   at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:205)
   at org.hibernate.collection.PersistentBag.add(PersistentBag.java:297)
   at it.polimi.data.hibernate.entities.Journal.addArticle(Journal.java:55)
   at it.polimi.crawler.IEEECrawlerNew.getYearArticles(IEEECrawlerNew.java:209)
   at applications.Crawler.main(Crawler.java:106)


Is it possible to add a new object into the collection in Journal without causing this error?


Top
 Profile  
 
 Post subject: Re: OutOfMemoryError working with blobs
PostPosted: Mon Feb 15, 2010 11:24 am 
Newbie

Joined: Sun Feb 14, 2010 7:13 pm
Posts: 6
The collection I used in Journal is a Vector, but it is not required that I use it. If I would use a Set or something else it would help solving my problem?


Top
 Profile  
 
 Post subject: Re: OutOfMemoryError working with blobs
PostPosted: Fri Feb 19, 2010 10:17 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The OutOfMemoryError wont' be solved by the collection type. Are you sure it's not just that - too much memory being used when loading in those objects?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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