I have a spring Web Service, where I have a DAO with one method add() which is annotated with @Transactional like below:
class MyDAOClass {
@Transactional(rollbackFor = Exception.class)
add(){
doAdd1();
doAdd2();
doAdd3();
}
...
doAdd2() throws MyException {
throw new MyException ("My Exception Message");
}
...
}
The service layer:
Now when I call the webservice, the service layer internally calls the add() method of this class. The service layer catches MyException e and gets the message and puts in the response object which is marshalled and sent back to the client. But, when the doAdd2() method throws the exception, the transaction is rolled back, and instead of "My Exception Message" , i get the following error message on the client side:
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">Transaction rolled back because it has been marked as rollback-only</faultstring>
</SOAP-ENV:Fault>