Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.3.3
-
Fix Version/s: 2.0.0
-
Labels:None
-
Number of attachments :
Description
Copy/pasting the initial report on the forum.
My use case is pretty simple. I have a JPA PersonEntity with a
uniqueId that I can set to whatever value. The uniqueId is associated
to a unique constraint in the database. In one of my tests, I start a
transaction and create the person with a uniqueID that already exists
in the database. When the JPA/Hibernate transaction commits, I get
this:
org.hibernate.exception.ConstraintViolationException: Could not
execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
at bitronix.tm.BitronixTransaction.fireBeforeCompletionEvent(BitronixTransaction.java:429)
at bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:173)
at bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:103)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1028)
What I am expecting is to get this exception in the caller and have
the transaction rolledback. What I get instead is this
org.springframework.transaction.UnexpectedRollbackException: JTA
transaction unexpectedly rolled back (maybe due to a timeout); nested
exception is bitronix.tm.internal.BitronixRollbackException:
transaction was marked as rollback only and has been rolled back
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1031)
It seems that the problem lies in the code or I misconfigured BTM
In BitronixTransaction, there is this piece of code
try {
if (log.isDebugEnabled()) log.debug("executing
synchronization " + synchronization);
synchronization.beforeCompletion();
} catch (RuntimeException ex) {
log.warn("Synchronization.beforeCompletion() call
failed for " + synchronization + ", marking transaction as rollback
only", ex);
setStatus(Status.STATUS_MARKED_ROLLBACK);
return;
}
The problem with this is that my runtime exception is caught, the
transaction is marked as rollbacked which is good from a transactional
standpoint but I don't get the error at all. What happens next is that
Spring finalize the commit of the transaction (since no exception was
raised) and realize that it has been set to rollbackOnly meanwhile,
leading to this exception.
Issue Links
- relates to
-
BTM-108
Exception not handled properly in beforeCompletion event during commit()
-
Actually the affect is 2.0.0-beta1. I haven't tried with 1.3.3