-->
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.  [ 10 posts ] 
Author Message
 Post subject: Out of memory in buildSessionFactory
PostPosted: Tue Jun 19, 2007 6:10 am 
Newbie

Joined: Mon Jun 18, 2007 9:14 am
Posts: 4
Location: Oslo, Norway
I have around 373 ecore classes which I want to persist in Hibernate. I'm using Eclipse 3.3M6/EMF/TENEO. Teneo creates a mapping file without problem, but buildSessionFactory runs out of memory. My Java heap space is set to the maximum to get eclipse run on my computer 1100MB.

I have profiled and debugged code and here is what I suspect.
There are 21 occurences of the following construct in my model. The is "items" reference property occurs in 21 different classes with the following definition. Entity is the root type common for all my classes.

class A implements Entity {

items [0:*] : Entity

}

the corresponding mapping file entry:

<joined-subclass name="A">
<key>
<column name="`entity_e_id`"/>
</key>
<idbag name="items" table="`A_items`" lazy="true" cascade="merge,persist,save-update,lock,refresh">
<collection-id column="ID" type="long">
<generator class="increment"/>
</collection-id>
<key/>
<many-to-many entity-name="Entity" unique="false"/>
</idbag>
</joined-subclass>

Each time the CascadeEntityJoinWalker get to an "items" entry it creates an association to the 373 subclasses of Entity. And it seems like this reqiures a lot of memory. I have tried to reduce the number of classes to 120 and then it works.

Is there any way to avoid this?

Regards
David

Hibernate version: 3.2.4.SP1

Full stack trace of any exception that occurs:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuffer.append(Unknown Source)
at org.hibernate.loader.JoinWalker.selectString(JoinWalker.java:953)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:93)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:78)
at org.hibernate.loader.AbstractEntityJoinWalker.initAll(AbstractEntityJoinWalker.java:58)
at org.hibernate.loader.entity.CascadeEntityJoinWalker.<init>(CascadeEntityJoinWalker.java:27)
at org.hibernate.loader.entity.CascadeEntityLoader.<init>(CascadeEntityLoader.java:25)
at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3013)
at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:2977)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildSessionFactory(HbSessionDataStore.java:156)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initialize(HbSessionDataStore.java:79)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 8:56 am 
Newbie

Joined: Mon Jun 18, 2007 6:26 pm
Posts: 3
I had this same problem. You should have better luck if you increase the PermGen space allocated to Eclipse by the Java VM.

You can read the details of the problem if you like, but the quick answer is below.

Locate the eclipse.ini configuration file.

Mac: {eclipse}/Eclipse.app/Contents/MacOS/eclipse.ini
( such as: /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini )


PC: {eclipse}/eclipse.ini
( such as: C:\Program Files\eclipse\eclipse.ini )


Where you see "-Xmx256m", make that "-Xmx512m".
Also add this argument right after it: "-XX:MaxPermSize=128m"


Your eclipse.ini file should now look something like this (excluding other options that may also be present):

-vmargs
-Xms40m
-Xmx512m
-XX:MaxPermSize=128m


Restart Eclipse, and you should be okay now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 12:53 pm 
Newbie

Joined: Mon Jun 18, 2007 9:14 am
Posts: 4
Location: Oslo, Norway
I have allready set it to the maximum to get eclipse to run: Xmx1000m

I have even tried with -XX:MaxPermSize=128m

But I still get the same out of memory fault.

David


Top
 Profile  
 
 Post subject: use jconsole
PostPosted: Mon Jul 02, 2007 6:05 pm 
Newbie

Joined: Wed Jan 04, 2006 10:01 pm
Posts: 17
Use jconsole with sdk 1.5 or A.6 to see which part of memory is filling up, it is probably "permgen" as it is used by CGLIB. So increase it above 128m if required...

On windows 32 bits you have to make sure that teh total memory does not grow above 1520m or so


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 6:07 pm 
Newbie

Joined: Wed Jan 04, 2006 10:01 pm
Posts: 17
By the way the correct option is
-XX:MaxPermSize=256m


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 3:45 am 
Newbie

Joined: Mon Jun 18, 2007 9:14 am
Posts: 4
Location: Oslo, Norway
Sorry for the absense. I have been away on holiday.

The problem occurs when EntityLoader creates static select actions. A number of StringBuffer/String pairs are allocated and this eats up the memory.

David


Top
 Profile  
 
 Post subject: buildSessionFactory out of memory
PostPosted: Wed Oct 31, 2007 11:25 am 
Newbie

Joined: Wed Oct 31, 2007 11:10 am
Posts: 1
Hi,

I am getting the same problem using a union-subclass
mapping strategy. The hibernate.hbm.xml file was created using teneo.
I have created a hibernate.hbm.xml file using a joined-subclass
mapping strategy as well and this works correctly.

I have tried increasing the memory available and
also reduced the number of classes being persisted.
The out of memory exception still occurs.

Was a solution found for this problem?? in previous post
there is a link to a bug report to memory leak in eclipse 3.2. We are
using eclipse 3.3; not sure if that applies in our case.

any help is greatly appreciated.

Shane


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 7:40 am 
Newbie

Joined: Wed Nov 21, 2007 6:48 am
Posts: 4
Hi Dskog! Did you resolve this problem? what the solution? I'm experienced the same problem when EntityLoader creates static select actions


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 5:14 am 
Newbie

Joined: Mon Jun 18, 2007 9:14 am
Posts: 4
Location: Oslo, Norway
No I did not resolve the problem and can therefore not use Hibernate for my project.

I have tried several things:

1) to increase JVM heap space to maximum on my Windows XP SP2. It works on another machine which can set Xmx to 1700 (curtecy of Martin Taal, but he is probably not running 32 bits windows). Unfortunately my JVM exits if Xmx is set larger than 1040. Even if I have 4GB of physical ram available! I have set the /3GB switch in boot.ini, checked the available continuous memory blocks (with listdlls), but unfortunate only 1.17 MB is available to me. Some web pages suggest using rebase to move offending dlls to increase the free blocks, but I haven't tried it.

2) to annotate the references to the offending ecore model(s) as transient. But unfortunately teneo insist on mapping them and leave it up to Hibernate to decide if they are transient or not. Alas Hibernate still runs out of memory.


I suspect the problem is caused by the following statement in
org.hibernate.loader.Joinwalker.selectString()

StringBuffer buf = new StringBuffer( associations.size() * 100 )

In my case it allocates a large string buffer and returns it as a String (allocates twice the memory needed). This is done several times in succession. And I guess the garbage collection cannot cope with this during initialization. But I havent got the time to debug this anymore.



Regards
David

DSkog


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 6:20 am 
Newbie

Joined: Wed Nov 21, 2007 6:48 am
Posts: 4
Thanks David for your answer, I'll try somethings here.


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