-1

In my application I have a heap memory exception : I increase the heap memory with JVM argument but it doesn't solve the problem : Here is the exception :

`java.lang.OutOfMemoryError: Java heap space
at org.hibernate.type.ByteArrayBlobType.deepCopy(ByteArrayBlobType.java:76)
at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:374)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:184)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:52)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:844)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:82)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3049)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:399)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:512)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:506)
 `

Please Help thanks in advance

Khalilos
  • 721
  • 2
  • 9
  • 17
  • Maybe some malicious entity mapping (causing circular references) – Antoniossss Mar 17 '16 at 22:50
  • Can you paste the code of the Session initialization and query execution? – Roberto Linares Mar 17 '16 at 22:52
  • Check this other question with the same problem as you. Maybe is the same cause: http://stackoverflow.com/questions/30234995/hibernate-java-lang-outofmemoryerror-java-heap-space – Roberto Linares Mar 17 '16 at 22:53
  • 3
    You seem to be loading entities containing blobs, and these blobs probably contain large amounts of bytes. – JB Nizet Mar 17 '16 at 22:54
  • Yes I have entities containing blobs which are loaded on server startup, the server start well but when I try to list or modify these entities sometimes I have this error and the application steal work any help please thanks – Khalilos Mar 17 '16 at 22:59
  • I see it is a deep copy, which means you will have two big entities. Maybe you can just keep one or do modification on the original one. – Adam Lyu Mar 18 '16 at 00:37
  • Hibernate can use up your memory by handling blobs, here is a fix: https://forum.hibernate.org/viewtopic.php?p=2452481#p2452481 – inf3rno Jan 27 '17 at 02:01
  • Possible duplicate of [How to persist LARGE BLOBs (>100MB) in Oracle using Hibernate](http://stackoverflow.com/questions/9253323/how-to-persist-large-blobs-100mb-in-oracle-using-hibernate) – inf3rno Jan 27 '17 at 02:02

1 Answers1

0

Check if you are getting the instance of SessionFactory through some singleton mechanism. I had this problem when I started learning hibernate. You can check jvm performance using jconsole. Type jconsole in command prompt and check the performance variation and optimise the code

padippist
  • 1,178
  • 1
  • 16
  • 30