0

I'm facing a situation. I've got an entity whith a byte[] mapped by a @Lob in JPA with eclipseLink impelementation. And an oracle database...

My problem is when looping over a collection of entities, the byte[] stay in memory, so while having a lot of entities it's finished by a java heap space...

I've try to isolate my @lob in a sub entities with @Cacheable( false ), and clean entityManager cache. Both didn't work....

I've read here that maybe it should be linked to the implementation of eclipse link but I'm stuck...

Community
  • 1
  • 1
Samuel
  • 369
  • 1
  • 4
  • 9
  • If you are looping over a collection of entities, how are you freeing the memory? Without details, its hard to say this isn't just a problem with your application, such as having a heavily interconnected object model and keeping a reference to the root. You might also try lazily fetching the lob field by marking it lazy and using weaving http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving – Chris May 23 '14 at 13:16
  • A sorry you're right. I loop over ids and load entities inside the loop. – Samuel May 23 '14 at 13:33
  • Are you keeping a reference to those entities inside your loop? – Martin Baumgartner May 23 '14 at 13:43
  • And no I do not keep reference to any entity inside my loop. – Samuel May 23 '14 at 13:44
  • 1
    If you are using the same EntityManager instance for the loop, you should be aware that JPA requires it to keep a reference to managed entities - which is anything read in through it. Your entities cannot be gc'd until they are released, which is when the em is closed or cleared. – Chris May 23 '14 at 13:49
  • Thanks Chris It's help a lot. I'll try it looking that way – Samuel May 23 '14 at 13:56
  • And it's works..................... So a very big thanks to you Chris – Samuel May 23 '14 at 14:07
  • One last questuin for my understaning why a clear is working whereas a detach doesn't seems to work ? – Samuel May 23 '14 at 14:14
  • Clear removes everything, while if using detach, you might not have detached everything. If one object is left, depending on your object model, it could have references to many other objects in your graph preventing any of it from being garbage collected. – Chris May 26 '14 at 14:56

0 Answers0