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?