The same method, the different service calls, an exception is rolled back, an exception is not rolle
The method of serviceA
@ Override
@ Transactional (rollbackFor=Exception class)
Public List
ImportProject (MultipartFile file, Long userId) throws CustomException, IOException { If (file. IsEmpty ()) throw new CustomException (" file does not exist!" , the FILE_EMPTY_RESPONSE); List Data=https://bbs.csdn.net/topics/POIExcelReader.readExcelContent (file. GetInputStream (), the file. The getOriginalFilename (), 1, 17). {if (CollectionUtils. IsEmpty (data)) Throw new CustomException (" did not get to import the data ", the NORMAL_ERROR_RESPONSE); } The info (" import template data length - & gt;" + data. The size ()); Return importService. ImportProject (data, userId); } The method of serviceB @ Override @ Transactional (rollbackFor=Exception class) Public List ImportProject (MultipartFile file, Long userId) throws CustomException, IOException { If (file. IsEmpty ()) throw new CustomException (" file does not exist!" , the FILE_EMPTY_RESPONSE); List Data=https://bbs.csdn.net/topics/POIExcelReader.readExcelContent (file. GetInputStream (), the file. The getOriginalFilename (), 1, 17). {if (CollectionUtils. IsEmpty (data)) Throw new CustomException (" did not get to import the data ", the NORMAL_ERROR_RESPONSE); } The info (" import template data length - & gt;" + data. The size ()); Return importService. ImportProject (data, userId); } Same, call is in a place called separately, each test, the result an exception rollback, another is not rolled back. CodePudding user response:
The possibility of this issue should be the source of the call, for example to explain the Now have two service - ServiceA and ServiceB ControllerA and ControllerB ControllerA call ServiceA, configuration like you @ Transactional (rollbackFor=Exception. Class) effective transaction at this time, an error will be mixing roll, similarly ControllerB call ServiceB as There is now a ControllerC, there's a ServiceC, ServiceC configuration is @ Transactional (there is no written rollbackFor), when ServiceC ControllerC calls, call ServiceC ServiceA or ServiceB, at this time if the program isn't throw RunTimeException will not be rolled back (your CustomException not inherit RunTimeException), why not rolled back? Because spring the spread of the default behavior is PROPAGATION_REQUIRED, said the current affairs to support the current transaction, so the final effect of the transaction ServiceC affairs, and is not configured on ServiceC rolled back CodePudding user response:
reference 1/f, thin black camel died response: the possibility that the problem should be the source of the call, for example to explain the Now have two service - ServiceA and ServiceB ControllerA and ControllerB ControllerA call ServiceA, configuration like you @ Transactional (rollbackFor=Exception. Class) effective transaction at this time, an error will be mixing roll, similarly ControllerB call ServiceB as There is now a ControllerC, there's a ServiceC, ServiceC configuration is @ Transactional (there is no written rollbackFor), when ServiceC ControllerC calls, call ServiceC ServiceA or ServiceB, at this time if the program isn't throw RunTimeException will not be rolled back (your CustomException not inherit RunTimeException), why not rolled back? Because spring the spread of the default behavior is PROPAGATION_REQUIRED, said the current affairs to support the current transaction, so the final effect of the transaction ServiceC affairs, and is not configured on ServiceC rollback I'm sorry, the above may be said is wrong, the memory is not very clear CodePudding user response:
May I write is not too clear, ServiceA and ServiceB methods are invoked ServiceC access, and ServiceA are consistent, and the method of ServiceB wrote in a Controller called ServiceA is abnormal no rollback, call ServiceB is abnormal rolled back, after the test, find ServiceA cannot be rolled back, the whole class wrote a most simple example can rollback, temporarily haven't find the problem reason, and ServiceA class notes only @ service and @ slf4j two. ServiceB as well. Do not know to have may be a possible, the same service will affect the way I call the other methods. In fact in the called method is ServiceA didn't call any methods in this class. Didn't find the problem at all! CodePudding user response:
Now a problem need to know is what reason can cause the entire Service cannot be rolled back, also don't know why! CodePudding user response:
Said can't rollback is not very accurate, again a little bit deep, the transaction is invalid, use the manual force a rollback. There will be No transaction CodePudding user response:
That is about to be enhanced serviceA transaction there is no, look at the scan path of the package right ah, @ Transactional may not come into effect CodePudding user response:
Quote: refer to the third floor qq_35205242 response: May I write is not too clear, ServiceA and ServiceB methods are invoked ServiceC access, and ServiceA are consistent, and the method of ServiceB wrote in a Controller called ServiceA is abnormal no rollback, call ServiceB is abnormal rolled back, after the test, find ServiceA cannot be rolled back, the whole class wrote a most simple example can rollback, temporarily haven't find the problem reason, and ServiceA class notes only @ service and @ slf4j two. ServiceB as well. Do not know to have may be a possible, the same service will affect the way I call the other methods. In fact in the called method is ServiceA didn't call any methods in this class. Didn't find the problem at all! [/quote When Posting, you must enter the code, there is a code plug-in option. That code is easier to see. A service has rolled back, you said a no, then you look at the things of the project configuration items, also is in the XML configuration items, to path ServiceA does not scan, under the specified path is not in XML. CodePudding user response:
reference qq_35205242 reply: 3/f may I write is not too clear, ServiceA and ServiceB methods are invoked ServiceC access, and ServiceA are consistent, and the method of ServiceB wrote in a Controller called ServiceA is abnormal no rollback, call ServiceB is abnormal rolled back, after the test, find ServiceA cannot be rolled back, the whole class wrote a most simple example can rollback, temporarily haven't find the problem reason, and ServiceA class notes only @ service and @ slf4j two. ServiceB as well. Do not know to have may be a possible, the same service will affect the way I call the other methods. In fact in the called method is ServiceA didn't call any methods in this class. Didn't find the problem at all! When Posting, you must enter the code, there is a code plug-in option. That code is easier to see. A service has rolled back, you said a no, then you look at the things of the project configuration items, also is in the XML configuration items, to path ServiceA does not scan, under the specified path is not in XML. CodePudding user response:
Because, due to the problem of the whole project architecture, the possible reasons is still uncertain, Project is using springboot - data - jpa Opens the transaction management in start class, the default is the project under scanning all packages But serviceA an entire class of transaction can use reason don't know what's wrong, are normal configuration, @ service and @ transaction No other things CodePudding user response:
nullnullnullnullnullnull