JPAContainer and heap space exception

I’ve made an application with huge database. I iterate through the JPAContainer and do something for each record. After ± 45.000 records, I got “java.lang.OutOfMemoryError: Java heap space”. How to prevent this? Should I increasing the JVM memory’s Xmx or there is another way? Something about caching maybe?

45k rows is not that many usually (depending on your entity) . If you are modifying the entity, the EntityManager has to keep your entity in memory for duration of the Transaction. I suggest you make smaller batches for the Transactions ( every 1000 record or so commit )

Best bet is to break your entire job into batches ,
run for 1000 records commit/clear EntityManager ,
start again with a Criteria Filter set so the PK > last key used

It might be easier to use the
and use setBatchSize() on the LazyQueryDefinition ( still using the strategy as mentioned above )

Thanks for your reply. I’ll try that. For now, I have increased the heap size maximum to 1024m, and my project goes well untill the last row (± 560000)