Search code examples
springspring-transactions

Question on Spring Transaction and exception


I have been through few posts but i still can't understand my issue.

I have the following code :

@Component
class API{
...
public String getTranslations(){
    serviceLayer.getTranslations()
}
...
}

class ServiceLayer(){
....
public String getTranslations(){

...

for (final PulldownEntry docStructure : docStructures)
try{
    structure.getTranslations(docStructure .getId())
}
catch(Exception e){
 do nothing
}

}
....

}


class Structure{
....
@Transactional(propagation = Propagation.REQUIRED, noRollbackFor = Exception.class, readOnly = true)
public String getTranslations(Long structureId){

    DataStructure dataStructure = dao.getObject(structureId);
if(dataStructure.hasNoData())
throw CustomException();

return dataStructure .getXML():


}
....
}

When the exception is thrown i am getting "UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only" Why ?


Solution

  • Suppose it cab be related with this one: https://jira.spring.io/browse/SPR-9746

    The current workaround is to remove the readOnly flag.