0
votes

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>

1
I think a good design is to make service method should be transactional, rather than dao methodSubin Sebastian
@SubinS if i have to execute some other methods after the add() later, which should be executed even if the add() rolled back, is that possible if i use Transactional to the service method?wildnux
in that case make them seperate service methodsSubin Sebastian

1 Answers

0
votes

Nevermind. I found the issue. I had my service class also annotated with @Transactional. The problem solved after I removed the this annotation. I am just keeping it for those who might be wondering why they get this message.