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.
I solved it by catching
OutOfMemoryError
and rethrowing it asRuntimeException
. This produced proper rollback, garbage collection (because big object graph was released) and service could continue running.