How can catch the cause of rollback exception
when run the code below (here reason is unique constraint error ), I'm using Weblogic
, Spring
, Hibernate
, JTA
<tx:annotation-driven transaction-manager="txManager" order="200" />
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>
@Service
public class OrderService extend BaseService<Order, Long> {
@Transactional
public Long save(Order modelEntity) {
try{
super.save(modelEntity);
}
catch(Exception exp){
....
}
}
}
------------------------------
@Controller
@RequestMapping("/test/core/Order")
public class OrderController extends BaseController{
@Autowired(required = true)
private IOrderService iOrderService;
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseBody
public Long save(@RequestBody Order modelEntity) {
return iOrderService.save(modelEntity);
}
}
@Controller
public class BaseController {
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ResponseEntity<String> handleUncaughtException(Exception ex, WebRequest request, HttpServletResponse response) throws IOException {
String logMessage = ex.toString() + " " + ex.getMessage();
if (ex.getCause()!= null) {
logMessage += ex.getCause().toString() + " " + ex.getCause().getMessage();
}
return new ResponseEntity<String>(" ", responseHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
}
[ERROR] org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: setRollbackOnly called on transaction JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: setRollbackOnly called on transactionweblogic.transaction.RollbackException: setRollbackOnly called on transaction setRollbackOnly called on transactionorg.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: setRollbackOnly called on transaction