I have the following code:
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Car prepareCar(Data data) throws CarServiceException{
Car car = null;
try {
car = carManagerBean.createCar(data);
Driver driver = createDriver();
car.setDriver(driver);
} catch (Exception e) {
LOGGER.error(e.getMessage, e);
context.setRollbackOnly();
throw new CarServiceException(e);
}
return car;
}
The problem is that if some problems appear in try section (e.g. SQLServerException) catch section is not executed and CarServiceException is not thrown. Does anybody know what might be the problem with this code? But the transaction is rolled back anyway. It works only if I move try-catch block to wrap the method call.