TransactionInterceptorΒΆ
‘Action methods’ annotated with Transactional will be enveloped in a transaction state; if exception arise the Transaction interceptor will do rollback automatically. Note the difference between pmis Transactional and spring Transactional annotation!
@pmis.system.spring.Transactional
public String methodName(){
...
return SUCCESS;
}
// NOT REQUIRED ANYMORE
@org.springframework.transaction.annotation.Transactional
public String methodName(){
try{
...
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
...
}
See also
Spring TransactionInterceptor valid for ‘non action class’ ( service class )
Important
To make the rolling back procedure work correctly a RuntimeException have to be thrown!!!
Note
Using TransactionInterceptor, is not required to explicitly throw a RuntimeException inside an action method, every exception will be catched and a rollback will be executed anyway.
However if you plan to execute a service without a web request (no action) you have to explicitly throw an unchecked exception (RuntimeException) in order to rollback the transaction in case of errors.
@org.springframework.transaction.annotation.Transactional( propagation = Propagation.REQUIRED )
public void transTest() throws Exception{
throw new RuntimeException(); // roolback WORK
//throw new Exception(); // roolback NOT WORK
}
Note
The interceptor used for service classes is the native Spring class: org.springframework.transaction.interceptor.TransactionInterceptor
Note
The interceptor used for action classes is the class: pmis.common.struts.interceptor.TransactionInterceptor