JPA concurrency issue "On release of batch it still contained JDBC statements"

I found this question getting same error. In my case the problem was caused by weird combination of trigger and row lock (see PSQLException and lock issue when trigger added on table). However it took some time to discover this error is just consequence of primary error, not the cause. When Hibernate flushes session and some constraint violation happens, it receives some JDBC exception and in the finally block it tries to call abortBatch. When any statement remains in session, Hibernate emits this warning, though the actual error should be search for somewhere before.


You cannot do that - once you flush something and it fails and an exception is thrown, the transaction will be marked as roll back. That means it doesnt matter that you catch the exception and proceed, you'll end up with a rollback. Actually it doesnt matter at all what exception was thrown - by default Spring's transaction manager will rollback on every unchecked exception. You can overcome it by specifically defining a noRollbackFor on the @Transactional annotation (providing you are using annotation driver transactions)

Edit - it also won't help you in case of this constraint violation, since the transaction will be probably marked as rollback at the database level.