diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 1edca6715c5..351da8495e0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -289,20 +289,20 @@ public class MonitoringManagerImpl implements MonitoringManager { PolicyManagementDAOFactory.closeConnection(); } - try { - PolicyManagementDAOFactory.beginTransaction(); - if (!firstTimeComplianceData.isEmpty()) { + if (!firstTimeComplianceData.isEmpty()) { + try { + PolicyManagementDAOFactory.beginTransaction(); monitoringDAO.addComplianceDetails(firstTimeComplianceData); PolicyManagementDAOFactory.commitTransaction(); + } catch (MonitoringDAOException e) { + PolicyManagementDAOFactory.rollbackTransaction(); + throw new PolicyComplianceException("Error occurred from monitoring dao.", e); + } catch (PolicyManagerDAOException e) { + PolicyManagementDAOFactory.rollbackTransaction(); + throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e); + } finally { + PolicyManagementDAOFactory.closeConnection(); } - } catch (MonitoringDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new PolicyComplianceException("Error occurred from monitoring dao.", e); - } catch (PolicyManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e); - } finally { - PolicyManagementDAOFactory.closeConnection(); } if (!notifiableDeviceEnrollments.isEmpty()) {