@@ -261,7 +261,8 @@ public <T> T execute(@Nullable TransactionDefinition definition, TransactionCall
261
261
"Transaction propagation 'nested' not supported for WebSphere UOW transactions" );
262
262
}
263
263
if (pb == TransactionDefinition .PROPAGATION_SUPPORTS ||
264
- pb == TransactionDefinition .PROPAGATION_REQUIRED || pb == TransactionDefinition .PROPAGATION_MANDATORY ) {
264
+ pb == TransactionDefinition .PROPAGATION_REQUIRED ||
265
+ pb == TransactionDefinition .PROPAGATION_MANDATORY ) {
265
266
joinTx = true ;
266
267
newSynch = (getTransactionSynchronization () != SYNCHRONIZATION_NEVER );
267
268
}
@@ -279,7 +280,8 @@ else if (pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
279
280
"Transaction propagation 'mandatory' but no existing transaction found" );
280
281
}
281
282
if (pb == TransactionDefinition .PROPAGATION_SUPPORTS ||
282
- pb == TransactionDefinition .PROPAGATION_NOT_SUPPORTED || pb == TransactionDefinition .PROPAGATION_NEVER ) {
283
+ pb == TransactionDefinition .PROPAGATION_NOT_SUPPORTED ||
284
+ pb == TransactionDefinition .PROPAGATION_NEVER ) {
283
285
uowType = UOWSynchronizationRegistry .UOW_TYPE_LOCAL_TRANSACTION ;
284
286
newSynch = (getTransactionSynchronization () == SYNCHRONIZATION_ALWAYS );
285
287
}
@@ -293,26 +295,31 @@ else if (pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
293
295
logger .debug ("Creating new transaction with name [" + definition .getName () + "]: " + definition );
294
296
}
295
297
SuspendedResourcesHolder suspendedResources = (!joinTx ? suspend (null ) : null );
298
+ UOWActionAdapter <T > action = null ;
296
299
try {
297
300
if (definition .getTimeout () > TransactionDefinition .TIMEOUT_DEFAULT ) {
298
301
uowManager .setUOWTimeout (uowType , definition .getTimeout ());
299
302
}
300
303
if (debug ) {
301
304
logger .debug ("Invoking WebSphere UOW action: type=" + uowType + ", join=" + joinTx );
302
305
}
303
- UOWActionAdapter < T > action = new UOWActionAdapter <>(
306
+ action = new UOWActionAdapter <>(
304
307
definition , callback , (uowType == UOWManager .UOW_TYPE_GLOBAL_TRANSACTION ), !joinTx , newSynch , debug );
305
308
uowManager .runUnderUOW (uowType , joinTx , action );
306
309
if (debug ) {
307
310
logger .debug ("Returned from WebSphere UOW action: type=" + uowType + ", join=" + joinTx );
308
311
}
309
312
return action .getResult ();
310
313
}
311
- catch (UOWException ex ) {
312
- throw new TransactionSystemException ("UOWManager transaction processing failed" , ex );
313
- }
314
- catch (UOWActionException ex ) {
315
- throw new TransactionSystemException ("UOWManager threw unexpected UOWActionException" , ex );
314
+ catch (UOWException | UOWActionException ex ) {
315
+ TransactionSystemException tse =
316
+ new TransactionSystemException ("UOWManager transaction processing failed" , ex );
317
+ Throwable appEx = action .getException ();
318
+ if (appEx != null ) {
319
+ logger .error ("Application exception overridden by rollback exception" , appEx );
320
+ tse .initApplicationException (appEx );
321
+ }
322
+ throw tse ;
316
323
}
317
324
finally {
318
325
if (suspendedResources != null ) {
@@ -368,12 +375,15 @@ public void run() {
368
375
}
369
376
catch (Throwable ex ) {
370
377
this .exception = ex ;
378
+ if (status .isDebug ()) {
379
+ logger .debug ("Rolling back on application exception from transaction callback" , ex );
380
+ }
371
381
uowManager .setRollbackOnly ();
372
382
}
373
383
finally {
374
384
if (status .isLocalRollbackOnly ()) {
375
385
if (status .isDebug ()) {
376
- logger .debug ("Transactional code has requested rollback" );
386
+ logger .debug ("Transaction callback has explicitly requested rollback" );
377
387
}
378
388
uowManager .setRollbackOnly ();
379
389
}
@@ -396,6 +406,11 @@ public T getResult() {
396
406
return this .result ;
397
407
}
398
408
409
+ @ Nullable
410
+ public Throwable getException () {
411
+ return this .exception ;
412
+ }
413
+
399
414
@ Override
400
415
public boolean isRollbackOnly () {
401
416
return obtainUOWManager ().getRollbackOnly ();
0 commit comments