Spring can commit Transaction in finally block with RunTimeException in try block [migrated]
- by Chance Lai
The project used Spring + Hibernate
Sample code:
public void method(){
try{
dao.saveA(entityA);
throw RuntimeException;
dao.saveB(entityB);
}catch(RuntimeException e){
throw e;
}finally{
dao.saveC(entityC)
}
}
Finally, just entityC will be saved in database in test.
I think saveA, saveB, saveC in the same transaction,they should not be committed.
In this case, I want to know why entityC is committed.
How does Spring do this in the finally block?