Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

why TransactionTemplate doesnt support rollback rules

$
0
0
Code:

RuleBasedTransactionAttribute rules = new RuleBasedTransactionAttribute();
rules.getRollbackRules().add(new NoRollbackRuleAttribute(RuntimeException.class));
 
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager,rules);
 
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
 
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
 
if(true) throw new RuntimeException();
 
}
});

I created above sample to test if TransactionTemplate takes rollback rules into account, but it doesnt. After that I looked inside execute method of TransactionTemplate and noticed that It rollbacks on any kind of exception.

Is there anyone who can explain the logic behind such implementation? I think it would be nice to give custom rollback rules to TransactionTemplate to change rollback logic on exception occurence. Or am I simply wrong?

Viewing all articles
Browse latest Browse all 297

Trending Articles