0

When my system gets "OutOfMemoryError: Java heap space", it commits the transaction (marked with org.apache.deltaspike.jpa.api.transaction.Transactional annotation).

How to avoid this and make a rollback instead? "Regular" exceptions do cause the rollback.

My JPA implementation is EclipseLink 2.6.4 and container is Tomcat 8.5.33 running with Java 8.

Aivar
  • 6,814
  • 5
  • 46
  • 78
  • Not sure if it possible maybe there is no heap space to perform anything anymore? So get rid of the OutOfMemoryError at first place. – pirho Jan 11 '19 at 15:58
  • commit should never be automatic. How is this transaction setup? – Chris Jan 13 '19 at 14:29
  • The method is annotated with `org.apache.deltaspike.jpa.api.transaction.Transactional`, this means transaction is started at method entry and ended (either committed on rolled back) on method exit. – Aivar Jan 13 '19 at 18:28
  • And how are you sure the OutOfMemoryError is occurring within the transaction itself and not post transaction commit? – Chris Jan 16 '19 at 15:32
  • @Chris, the actions in the transaction remain incomplete. – Aivar Jan 16 '19 at 20:17
  • You have a major server bug then, as an OOM should not cause its transaction handling to commit, and your application should never try to catch it. You are creating a new object (RuntimeException) - even that could get another OOM. – Chris Jan 17 '19 at 15:56
  • @Chris, in my case it seems to work, because by the time OutOfMemoryError is caught, JPA seems to have released the stuff that caused the OOM. – Aivar Jan 17 '19 at 23:07

1 Answers1

0

I solved it by catching OutOfMemoryError and rethrowing it as RuntimeException. This produced proper rollback, garbage collection (because big object graph was released) and service could continue running.

Aivar
  • 6,814
  • 5
  • 46
  • 78