Search code examples
out-of-memoryopenjparecursive-query

OutofMemory Exception occuring with OpenJPA


I am getting an out of memory error when I attempt to pull back a huge tree of objects using openJPA... what can I do to alleviate this... Here is a bit of my methodology...

I search for an entity... This entity should have child entities associated with it (which are esesntially the same entity)... So I include a List of children with it...

private List<Organization> childOrgsTree = new ArrayList<Organization>();

So the entity is an organization and I include a list of organizations with this entity... Now I have a named native query that gets every child of this particular entity. I recursively loop through each of those children and find each child of that entity... Making that same named native query call probably thousands of time. Constructing the child tree objects recursively. Now, this seems to work, until I run into an out of Memory Exception... I am a little flumoxed how I can get around this little problem? I obviously could just increase the memory allocated to the process, but I fear that would be a bandaid. Any ideas?


Solution

  • I am a little flumoxed how I can get around this little problem?

    You have two options, hold on to less memory in your application code, or increase the JVM heap size.