stop throwing javax.persistence.RollbackException: Transaction marked as rollbackOnly

325
May 10, 2018, at 04:56 AM

I have the implement a service like this.

@Service
public class Service1 {
    @Autowired
    Service2 service2;
    @Autowired
    Service3 service3;
    @Transactional
    methodB() {
        if(true) {
            throw new Exception("Reason 1");
        }
    }
    @Transactional
    methodC() {
        if(true) {
            throw new Exception("Reason 2");
        }
    }
    @Transactional
    Response methodA() {
        try {
            methodB();
            methodC();
            service2.methodD();
            service3.methodE();
            return new Response(Status.OK);
        } catch(Exception e) {
            return new Response(e.printStackTrace());
        }
    }   
}
@Service
public class Service2 {
    @Transactional
    methodD() {
        if(true) {
            throw new Exception("Reason 3");
        }
    }
}
@Service
public class Service3 {
    @Transactional
    methodE() {
        if(true) {
            throw new Exception("Reason 4");
        }
    }
}

When I get a error in service2.methoD() it throws the Exception: "Reason 3" and is catched in methodA() and is supposed to return the reason of the exception. But then I get the exception: javax.persistence.RollbackException: Transaction marked as rollbackOnly and it is what is finally returned. I don't want to return this exception instead the first exception, how can achieve that?

PD: It's supposed to rollback the entire methodA transaction if a error occurs and it is what is happening so there is no problem with that.

Thanks.

Rent Charter Buses Company
READ ALSO
Is There a Way to Make a NULL Value Act as an Optional Condition in MySql?

Is There a Way to Make a NULL Value Act as an Optional Condition in MySql?

I'm trying to write a JDBC query with 20 optional search parametersI would like to know how to make a set of parameters that do not have a value (null) not to be included in the SQL without having too many if/else statements to construct the SQL string...

166
Create csv file and send as attachment

Create csv file and send as attachment

So I'm trying to generate a csv file and then immediately send it as an attachment

147
Regex for phone number with '+' [on hold]

Regex for phone number with '+' [on hold]

I need a regex for a phone number which should cater to this:

154