OpenJPA Integration Changes

Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/9d7f1c21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/9d7f1c21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/9d7f1c21

Branch: refs/heads/develop
Commit: 9d7f1c2197dff20b4a977b77670b04e26cfcc2e1
Parents: 8d3f7af
Author: Nazeer Hussain Shaik <nazeer.sh...@confluxtechnologies.com>
Authored: Mon Oct 17 11:46:52 2016 +0530
Committer: Nazeer Hussain Shaik <nazeer.sh...@confluxtechnologies.com>
Committed: Mon Oct 17 11:46:52 2016 +0530

----------------------------------------------------------------------
 fineract-provider/build.gradle                  | 22 +++---
 fineract-provider/dependencies.gradle           |  4 +-
 fineract-provider/dev-dependencies.gradle       |  4 +-
 .../common/ProvisioningIntegrationTest.java     | 26 ++++---
 .../closure/domain/GLClosureRepository.java     |  2 +-
 .../domain/FinancialActivityAccount.java        |  4 +-
 .../FinancialActivityAccountRepository.java     |  2 +-
 ...ActivityAccountWritePlatformServiceImpl.java | 18 +++--
 .../accounting/glaccount/domain/GLAccount.java  |  6 +-
 .../domain/JournalEntryRepository.java          | 12 ++--
 .../domain/ProductToGLAccountMapping.java       | 17 +++--
 .../ProductToGLAccountMappingRepository.java    |  8 +--
 .../domain/LoanProductProvisioningEntry.java    |  4 +-
 .../provisioning/domain/ProvisioningEntry.java  |  6 +-
 .../domain/ProvisioningEntryRepository.java     |  5 +-
 .../accounting/rule/domain/AccountingRule.java  |  6 +-
 .../rule/domain/AccountingRuleRepository.java   |  2 +-
 .../rule/domain/AccountingTagRule.java          |  4 +-
 .../fineract/batch/exception/ErrorHandler.java  |  3 +
 .../batch/service/BatchApiServiceImpl.java      | 18 ++++-
 .../fineract/commands/domain/CommandSource.java |  4 +-
 .../domain/AccountNumberFormat.java             |  6 +-
 .../domain/AccountNumberFormatRepository.java   |  2 +-
 ...atWritePlatformServiceJpaRepositoryImpl.java | 22 ++++--
 .../cache/domain/PlatformCache.java             |  4 +-
 .../infrastructure/codes/domain/Code.java       |  6 +-
 .../infrastructure/codes/domain/CodeValue.java  |  4 +-
 ...deWritePlatformServiceJpaRepositoryImpl.java | 20 ++++--
 .../configuration/domain/ExternalService.java   |  4 +-
 .../domain/ExternalServicePropertiesPK.java     | 28 ++++++++
 .../domain/ExternalServicesProperties.java      |  2 -
 .../ExternalServicesPropertiesRepository.java   |  5 +-
 ...rnalServicesPropertiesRepositoryWrapper.java |  2 +-
 .../domain/GlobalConfigurationProperty.java     |  8 +--
 .../core/data/ApiParameterError.java            | 11 ++-
 .../core/domain/AbstractAuditableCustom.java    | 21 +++---
 .../core/domain/AbstractPersistableCustom.java  | 70 ++++++++++++++++++
 .../core/domain/MySQLDictionaryCustom.java      | 46 ++++++++++++
 .../TomcatJdbcDataSourcePerTenantService.java   |  3 +-
 .../dataqueries/domain/Report.java              |  6 +-
 .../dataqueries/domain/ReportParameter.java     |  4 +-
 .../domain/ReportParameterUsage.java            | 10 ++-
 .../ReadWriteNonCoreDataServiceImpl.java        | 72 ++++++++++++++++++-
 .../service/ReportWritePlatformServiceImpl.java | 20 ++++--
 .../documentmanagement/domain/Document.java     |  4 +-
 .../documentmanagement/domain/Image.java        |  4 +-
 .../domain/FineractEntityAccess.java            |  4 +-
 .../domain/FineractEntityRelation.java          |  4 +-
 .../FineractEntityRelationRepository.java       |  2 +-
 .../domain/FineractEntityToEntityMapping.java   |  8 +--
 ...FineractEntityToEntityMappingRepository.java |  2 +-
 .../FineractEntityAccessWriteServiceImpl.java   | 20 ++++--
 .../hooks/domain/HookConfiguration.java         |  4 +-
 .../hooks/domain/HookRepository.java            |  4 +-
 .../hooks/domain/HookResource.java              |  4 +-
 .../hooks/domain/HookTemplate.java              |  6 +-
 .../hooks/domain/HookTemplateRepository.java    |  2 +-
 .../infrastructure/hooks/domain/Schema.java     |  6 +-
 ...okWritePlatformServiceJpaRepositoryImpl.java | 58 ++++++++++-----
 .../jobs/domain/ScheduledJobDetail.java         |  4 +-
 .../domain/ScheduledJobDetailRepository.java    |  6 +-
 .../jobs/domain/ScheduledJobRunHistory.java     |  4 +-
 .../jobs/domain/SchedulerDetail.java            |  4 +-
 .../domain/ReportMailingJobConfiguration.java   |  4 +-
 .../domain/ReportMailingJobRunHistory.java      |  4 +-
 .../infrastructure/sms/domain/SmsMessage.java   |  4 +-
 .../survey/domain/Likelihood.java               |  4 +-
 .../survey/domain/LikelihoodRepository.java     |  2 +-
 .../fineract/mix/domain/MixTaxonomyMapping.java |  4 +-
 .../organisation/holiday/domain/Holiday.java    |  4 +-
 .../holiday/domain/HolidayRepository.java       |  2 +-
 ...ayWritePlatformServiceJpaRepositoryImpl.java | 18 +++--
 .../monetary/domain/ApplicationCurrency.java    | 16 ++---
 .../monetary/domain/MonetaryCurrency.java       |  6 +-
 .../organisation/monetary/domain/Money.java     |  8 +--
 .../organisation/office/domain/Office.java      |  6 +-
 .../office/domain/OfficeTransaction.java        |  4 +-
 .../office/domain/OrganisationCurrency.java     | 16 ++---
 ...ceWritePlatformServiceJpaRepositoryImpl.java | 18 +++--
 .../domain/LoanProductProvisionCriteria.java    |  4 +-
 .../domain/ProvisioningCategory.java            |  4 +-
 .../domain/ProvisioningCriteria.java            |  2 +-
 .../domain/ProvisioningCriteriaDefinition.java  |  5 +-
 ...ryWritePlatformServiceJpaRepositoryImpl.java | 18 +++--
 ...iaWritePlatformServiceJpaRepositoryImpl.java | 21 ++++--
 .../organisation/staff/domain/Staff.java        | 18 +++--
 ...ffWritePlatformServiceJpaRepositoryImpl.java | 18 +++--
 .../organisation/teller/domain/Cashier.java     |  4 +-
 .../teller/domain/CashierTransaction.java       |  8 +--
 .../organisation/teller/domain/Teller.java      | 30 ++++----
 .../teller/domain/TellerRepositoryWrapper.java  | 15 ++++
 .../teller/domain/TellerTransaction.java        |  4 +-
 .../TellerWritePlatformServiceJpaImpl.java      | 68 +++++++++++-------
 .../workingdays/domain/WorkingDays.java         |  4 +-
 .../account/domain/AccountAssociations.java     |  4 +-
 .../domain/AccountAssociationsRepository.java   |  4 +-
 .../account/domain/AccountTransferDetails.java  |  8 +--
 .../domain/AccountTransferRepository.java       |  8 +--
 .../AccountTransferStandingInstruction.java     |  4 +-
 .../domain/AccountTransferTransaction.java      |  4 +-
 .../portfolio/address/domain/Address.java       |  4 +-
 .../address/domain/FieldConfiguration.java      |  4 +-
 .../calendar/domain/CalendarHistory.java        |  4 +-
 .../calendar/domain/CalendarInstance.java       |  4 +-
 .../domain/CalendarInstanceRepository.java      |  4 +-
 .../portfolio/charge/domain/Charge.java         |  4 +-
 .../service/ChargeReadPlatformServiceImpl.java  | 33 ++++-----
 ...geWritePlatformServiceJpaRepositoryImpl.java | 20 ++++--
 .../portfolio/client/domain/Client.java         | 18 ++---
 .../portfolio/client/domain/ClientAddress.java  |  4 +-
 .../portfolio/client/domain/ClientCharge.java   |  4 +-
 .../client/domain/ClientChargePaidBy.java       |  4 +-
 .../client/domain/ClientNonPerson.java          |  4 +-
 .../domain/ClientNonPersonRepository.java       |  2 +-
 .../client/domain/ClientTransaction.java        |  4 +-
 .../ClientTransactionRepositoryWrapper.java     |  2 +-
 ...geWritePlatformServiceJpaRepositoryImpl.java |  3 +-
 ...erWritePlatformServiceJpaRepositoryImpl.java | 25 ++++---
 ...ntWritePlatformServiceJpaRepositoryImpl.java | 24 +++++--
 .../collateral/domain/LoanCollateral.java       | 10 ++-
 .../floatingrates/domain/FloatingRate.java      | 45 ++++--------
 .../domain/FloatingRatePeriod.java              |  9 +--
 .../domain/FloatingRateRepository.java          | 10 +--
 .../FloatingRateWritePlatformServiceImpl.java   | 22 ++++--
 .../fineract/portfolio/fund/domain/Fund.java    |  4 +-
 ...ndWritePlatformServiceJpaRepositoryImpl.java | 19 +++--
 .../fineract/portfolio/group/domain/Group.java  |  8 +--
 .../portfolio/group/domain/GroupLevel.java      | 10 +--
 .../portfolio/group/domain/GroupRole.java       |  4 +-
 ...esWritePlatformServiceJpaRepositoryImpl.java | 28 ++++++--
 .../domain/InterestIncentives.java              |  4 +-
 .../domain/InterestRateChart.java               |  6 +-
 .../domain/InterestRateChartFields.java         |  2 +-
 .../domain/InterestRateChartSlab.java           |  6 +-
 .../domain/InterestRateChartSlabFields.java     |  2 +-
 .../portfolio/loanaccount/domain/Loan.java      | 75 ++++++++++++++++----
 .../loanaccount/domain/LoanCharge.java          | 21 +++---
 .../loanaccount/domain/LoanChargePaidBy.java    |  4 +-
 .../domain/LoanDisbursementDetails.java         |  4 +-
 .../domain/LoanInstallmentCharge.java           |  4 +-
 ...nInterestRecalcualtionAdditionalDetails.java |  4 +-
 .../LoanInterestRecalculationDetails.java       |  4 +-
 .../domain/LoanOverdueInstallmentCharge.java    |  4 +-
 .../LoanRepaymentScheduleInstallment.java       |  3 +-
 .../loanaccount/domain/LoanRepository.java      | 34 ++++-----
 .../domain/LoanRepositoryWrapper.java           |  1 +
 ...RescheduleRequestToTermVariationMapping.java |  5 +-
 .../loanaccount/domain/LoanTermVariations.java  |  5 +-
 .../loanaccount/domain/LoanTopupDetails.java    | 15 ++--
 .../loanaccount/domain/LoanTrancheCharge.java   |  4 +-
 .../domain/LoanTrancheDisbursementCharge.java   |  5 +-
 .../loanaccount/domain/LoanTransaction.java     | 18 ++---
 ...anTransactionToRepaymentScheduleMapping.java |  4 +-
 .../loanaccount/guarantor/domain/Guarantor.java |  6 +-
 .../domain/GuarantorFundingDetails.java         |  6 +-
 .../domain/GuarantorFundingTransaction.java     |  4 +-
 .../GuarantorFundingTransactionRepository.java  |  2 +-
 .../domain/AbstractLoanScheduleGenerator.java   | 50 ++++++-------
 .../domain/LoanRepaymentScheduleHistory.java    |  4 +-
 .../domain/LoanRescheduleRequest.java           |  4 +-
 ...onWritePlatformServiceJpaRepositoryImpl.java | 28 +++++---
 .../service/LoanArrearsAgingServiceImpl.java    |  1 -
 .../service/LoanChargeAssembler.java            | 11 ++-
 .../loanproduct/domain/LoanProduct.java         |  6 +-
 .../LoanProductBorrowerCycleVariations.java     |  4 +-
 .../LoanProductConfigurableAttributes.java      |  6 +-
 .../domain/LoanProductFloatingRates.java        |  4 +-
 .../domain/LoanProductGuaranteeDetails.java     |  8 +--
 ...LoanProductInterestRecalculationDetails.java |  4 +-
 .../domain/LoanProductTrancheDetails.java       |  4 +-
 .../LoanProductVariableInstallmentConfig.java   |  4 +-
 .../LoanTransactionProcessingStrategy.java      |  4 +-
 .../productmix/domain/ProductMix.java           |  4 +-
 .../productmix/domain/ProductMixRepository.java |  4 +-
 ...ctWritePlatformServiceJpaRepositoryImpl.java | 27 ++++---
 .../attendance/domain/ClientAttendance.java     |  4 +-
 .../portfolio/meeting/domain/Meeting.java       |  4 +-
 .../fineract/portfolio/note/domain/Note.java    |  4 +-
 .../paymentdetail/domain/PaymentDetail.java     |  4 +-
 .../paymenttype/domain/PaymentType.java         |  4 +-
 .../domain/DepositAccountInterestIncentive.java |  4 +-
 .../DepositAccountInterestIncentives.java       |  4 +-
 .../domain/DepositAccountInterestRateChart.java |  4 +-
 .../DepositAccountInterestRateChartSlabs.java   |  4 +-
 .../domain/DepositAccountOnHoldTransaction.java |  4 +-
 .../domain/DepositAccountRecurringDetail.java   |  8 +--
 .../domain/DepositAccountTermAndPreClosure.java |  6 +-
 .../domain/DepositProductRecurringDetail.java   |  4 +-
 .../domain/DepositProductTermAndPreClosure.java |  4 +-
 .../savings/domain/FixedDepositAccount.java     |  6 ++
 .../savings/domain/RecurringDepositAccount.java |  1 +
 .../RecurringDepositScheduleInstallment.java    |  6 +-
 .../savings/domain/SavingsAccount.java          | 10 +--
 .../savings/domain/SavingsAccountCharge.java    | 13 +---
 .../domain/SavingsAccountChargePaidBy.java      |  4 +-
 .../domain/SavingsAccountChargeRepository.java  |  2 +-
 .../domain/SavingsAccountRepository.java        | 14 ++--
 .../domain/SavingsAccountTransaction.java       | 24 +++----
 .../SavingsAccountTransactionTaxDetails.java    |  4 +-
 .../savings/domain/SavingsProduct.java          | 14 ++--
 ...ntWritePlatformServiceJpaRepositoryImpl.java | 20 +++---
 ...ssWritePlatformServiceJpaRepositoryImpl.java | 33 ++++++---
 ...ctWritePlatformServiceJpaRepositoryImpl.java | 20 ++++--
 ...ctWritePlatformServiceJpaRepositoryImpl.java | 21 ++++--
 ...ntWritePlatformServiceJpaRepositoryImpl.java | 22 +++---
 ...ssWritePlatformServiceJpaRepositoryImpl.java | 18 +++--
 ...ctWritePlatformServiceJpaRepositoryImpl.java | 21 ++++--
 .../account/domain/SelfBeneficiariesTPT.java    |  4 +-
 .../shareaccounts/domain/ShareAccount.java      |  4 +-
 .../domain/ShareAccountCharge.java              | 14 +---
 .../domain/ShareAccountChargePaidBy.java        |  4 +-
 .../domain/ShareAccountDividendDetails.java     |  4 +-
 .../domain/ShareAccountTransaction.java         |  6 +-
 .../ShareAccountDataSerializer.java             |  1 +
 ...ntWritePlatformServiceJpaRepositoryImpl.java | 39 ++++++----
 .../shareproducts/domain/ShareProduct.java      |  2 +-
 .../domain/ShareProductMarketPrice.java         |  4 +-
 ...ctWritePlatformServiceJpaRepositoryImpl.java | 43 +++++++----
 .../apache/fineract/spm/domain/Component.java   |  4 +-
 .../apache/fineract/spm/domain/LookupTable.java |  4 +-
 .../apache/fineract/spm/domain/Question.java    |  6 +-
 .../apache/fineract/spm/domain/Response.java    |  4 +-
 .../apache/fineract/spm/domain/Scorecard.java   |  4 +-
 .../org/apache/fineract/spm/domain/Survey.java  |  8 +--
 .../fineract/template/domain/Template.java      | 18 ++---
 .../template/domain/TemplateMapper.java         |  4 +-
 .../useradministration/domain/AppUser.java      |  8 +--
 .../domain/AppUserClientMapping.java            |  4 +-
 .../domain/AppUserPreviousPassword.java         |  4 +-
 .../domain/PasswordValidationPolicy.java        |  7 +-
 .../PasswordValidationPolicyRepository.java     |  2 +-
 .../useradministration/domain/Permission.java   | 12 ++--
 .../useradministration/domain/Role.java         |  6 +-
 .../domain/RoleRepository.java                  |  2 +-
 ...erWritePlatformServiceJpaRepositoryImpl.java | 30 +++++---
 ...leWritePlatformServiceJpaRepositoryImpl.java | 24 +++++--
 .../src/main/resources/META-INF/persistence.xml | 14 ++--
 .../META-INF/spring/infrastructure.xml          |  7 +-
 238 files changed, 1545 insertions(+), 914 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/build.gradle
----------------------------------------------------------------------
diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index 50e7e7a..b521d6c 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -23,6 +23,7 @@ gradle clean tomcatrunwar
 buildscript {
   repositories {
         jcenter()
+        mavenCentral()
   }
 
   dependencies {
@@ -30,6 +31,8 @@ buildscript {
                'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0',
                'org.zeroturnaround:gradle-jrebel-plugin:1.1.2',
                
'org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE' // also 
change springDataJpaVersion below
+     classpath 'org.apache.openjpa:openjpa-all:2.4.1'
+     classpath 'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
   }
 }
 
@@ -42,6 +45,7 @@ apply plugin: 'idea'
 apply plugin: 'tomcat'
 apply plugin: 'project-report'
 apply plugin: 'java'
+apply plugin: 'openjpa'
 
 /* define the valid syntax level for source files */
 sourceCompatibility = JavaVersion.VERSION_1_8
@@ -64,9 +68,16 @@ repositories {
        jcenter()
        // mavenLocal() // useful for local dev using MariaDB4j SNAPSHOTs (not 
needed for real-world non-SNAPHOT builds)
 }
+openjpa {
+    files = fileTree(sourceSets.main.output.classesDir).matching {
+               include '**/AbstractPersistableCustom.class'
+               include '**/domain/*.class'
+               
+    }
+    enforcePropertyRestrictions = true
+}
 
 configurations {
-       hibernateDependencies
        providedRuntime // needed for Spring Boot executable WAR
     providedCompile
        compile() {
@@ -136,11 +147,6 @@ task dist(type:Zip){
 
 war {
     war.finalizedBy(bootRepackage)
-       if (project.hasProperty('buildType') && 
project.getProperty('buildType') == 'TEST') {
-               from(configurations.hibernateDependencies) { // notice the 
parens
-               into "WEB-INF/lib/" // no leading slash
-    }
-       }
 }
 
 license {
@@ -200,7 +206,6 @@ sourceSets {
  integrationTest {
        compileClasspath += main.output + test.output
         runtimeClasspath += main.output + test.output
-        runtimeClasspath += configurations.hibernateDependencies
     }
 }
 
@@ -231,9 +236,6 @@ configurations {
 }
 dependencies {
     driver 'org.drizzle.jdbc:drizzle-jdbc:1.3'
-    hibernateDependencies(
-    [group:'org.springframework.boot', name:'spring-boot-starter-data-jpa', 
version:'1.1.6.RELEASE'],
-    ) 
 }
 
 test {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/dependencies.gradle
----------------------------------------------------------------------
diff --git a/fineract-provider/dependencies.gradle 
b/fineract-provider/dependencies.gradle
index dcb27fe..1623db7 100644
--- a/fineract-provider/dependencies.gradle
+++ b/fineract-provider/dependencies.gradle
@@ -37,11 +37,13 @@ dependencies {
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-web', version: springBootVersion],
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-data-jpa', version: springBootVersion],
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-security', version: springBootVersion],
-                               [group: 'org.eclipse.persistence', name: 
'javax.persistence', version: '2.0.0'],
+                               //[group: 'org.eclipse.persistence', name: 
'javax.persistence', version: '2.0.0'],
                 [group: 'org.springframework', name: 'spring-context-support', 
version: springVersion],
                                
                        [group: 'org.springframework.security.oauth', name: 
'spring-security-oauth2', version: springOauthVersion],
 
+                [group: 'org.apache.openjpa', name:'openjpa-all', 
version:'2.4.1'],
+                [group: 'org.apache.openjpa', name:'openjpa-maven-plugin', 
version:'2.4.1'],
                 [group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'],
                 [group: 'com.sun.jersey', name: 'jersey-core', version: 
jerseyVersion],
                 [group: 'com.sun.jersey', name: 'jersey-servlet', version: 
jerseyVersion],

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/dev-dependencies.gradle
----------------------------------------------------------------------
diff --git a/fineract-provider/dev-dependencies.gradle 
b/fineract-provider/dev-dependencies.gradle
index 82e4031..56fcb77 100644
--- a/fineract-provider/dev-dependencies.gradle
+++ b/fineract-provider/dev-dependencies.gradle
@@ -37,10 +37,12 @@ dependencies {
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-web', version: springBootVersion],
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-data-jpa', version: springBootVersion],
                 [group: 'org.springframework.boot', name: 
'spring-boot-starter-security', version: springBootVersion],
-                               [group: 'org.eclipse.persistence', name: 
'javax.persistence', version: '2.0.0'],
+                               //[group: 'org.eclipse.persistence', name: 
'javax.persistence', version: '2.0.0'],
                 [group: 'org.springframework', name: 'spring-context-support', 
version: springVersion],
                                [group: 'org.springframework.security.oauth', 
name: 'spring-security-oauth2', version: springOauthVersion],
 
+                               [group: 'org.apache.openjpa', 
name:'openjpa-all', version:'2.4.1'],
+                [group: 'org.apache.openjpa', name:'openjpa-maven-plugin', 
version:'2.4.1'],
                 [group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'],
                 [group: 'com.sun.jersey', name: 'jersey-core', version: 
jerseyVersion],
                 [group: 'com.sun.jersey', name: 'jersey-servlet', version: 
jerseyVersion],

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java
 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java
index 107bece..f07fdee 100644
--- 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java
+++ 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java
@@ -155,14 +155,24 @@ public class ProvisioningIntegrationTest {
         Assert.assertEquals(newdefintions.size(), requestedDefinitions.size()) 
;
         for(int i = 0 ; i < newdefintions.size() ; i++) {
             Map requestedMap = (Map)requestedDefinitions.get(i) ;
-            Map newMap = (Map)newdefintions.get(i) ;
-            checkProperty("categoryId", requestedMap, newMap) ;
-            checkProperty("categoryName", requestedMap, newMap) ;
-            checkProperty("minAge", requestedMap, newMap) ;
-            checkProperty("maxAge", requestedMap, newMap) ;
-            checkProperty("provisioningPercentage", requestedMap, newMap) ;
-            checkProperty("liabilityAccount", requestedMap, newMap) ;
-            checkProperty("expenseAccount", requestedMap, newMap) ;
+            Object requestedCategoryId = requestedMap.get("categoryId") ;
+            boolean found = false ; 
+            for(int j = 0 ; j < newdefintions.size(); j++) {
+               Map newMap = (Map)newdefintions.get(j) ;
+                Object newCategoryId = newMap.get("categoryId") ;
+                if(requestedCategoryId.equals(newCategoryId)) {
+                       found = true ;
+                    checkProperty("categoryId", requestedMap, newMap) ;
+                    checkProperty("categoryName", requestedMap, newMap) ;
+                    checkProperty("minAge", requestedMap, newMap) ;
+                    checkProperty("maxAge", requestedMap, newMap) ;
+                    checkProperty("provisioningPercentage", requestedMap, 
newMap) ;
+                    checkProperty("liabilityAccount", requestedMap, newMap) ;
+                    checkProperty("expenseAccount", requestedMap, newMap) ;
+                    break ; //internal loop
+                }
+            }
+            if(!found) Assert.fail("No Category found with 
Id:"+requestedCategoryId);
         }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosureRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosureRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosureRepository.java
index cc43547..75bfe7a 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosureRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/domain/GLClosureRepository.java
@@ -25,6 +25,6 @@ import org.springframework.data.repository.query.Param;
 
 public interface GLClosureRepository extends JpaRepository<GLClosure, Long>, 
JpaSpecificationExecutor<GLClosure> {
 
-    @Query("from GLClosure closure where closure.closingDate = (select 
max(closure1.closingDate) from GLClosure closure1 where 
closure1.office.id=:officeId)  and closure.office.id= :officeId")
+    @Query("select closure from GLClosure closure where closure.closingDate = 
(select max(closure1.closingDate) from GLClosure closure1 where 
closure1.office.id=:officeId)  and closure.office.id= :officeId")
     GLClosure getLatestGLClosureByBranch(@Param("officeId") Long officeId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccount.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccount.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccount.java
index 93f8e79..3f87468 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccount.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccount.java
@@ -26,11 +26,11 @@ import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 import org.apache.fineract.accounting.glaccount.domain.GLAccount;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "acc_gl_financial_activity_account")
-public class FinancialActivityAccount extends AbstractPersistable<Long> {
+public class FinancialActivityAccount extends AbstractPersistableCustom<Long> {
 
     @ManyToOne(fetch = FetchType.EAGER)
     @JoinColumn(name = "gl_account_id")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java
index 7414133..940b57b 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java
@@ -26,7 +26,7 @@ import org.springframework.data.repository.query.Param;
 public interface FinancialActivityAccountRepository extends 
JpaRepository<FinancialActivityAccount, Long>,
         JpaSpecificationExecutor<FinancialActivityAccount> {
 
-    @Query("from FinancialActivityAccount faa where faa.financialActivityType 
= :financialActivityType")
+    @Query("select faa from FinancialActivityAccount faa where 
faa.financialActivityType = :financialActivityType")
     FinancialActivityAccount 
findByFinancialActivityType(@Param("financialActivityType") int 
financialAccountType);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java
index 558cc41..c5e2e22 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java
@@ -21,6 +21,9 @@ package 
org.apache.fineract.accounting.financialactivityaccount.service;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import 
org.apache.fineract.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY;
 import 
org.apache.fineract.accounting.financialactivityaccount.api.FinancialActivityAccountsJsonInputParams;
 import 
org.apache.fineract.accounting.financialactivityaccount.domain.FinancialActivityAccount;
@@ -76,7 +79,11 @@ public class 
FinancialActivityAccountWritePlatformServiceImpl implements Financi
                     .withEntityId(financialActivityAccount.getId()) //
                     .build();
         } catch (DataIntegrityViolationException 
dataIntegrityViolationException) {
-            handleFinancialActivityAccountDataIntegrityIssues(command, 
dataIntegrityViolationException);
+            handleFinancialActivityAccountDataIntegrityIssues(command, 
dataIntegrityViolationException.getMostSpecificCause(), 
dataIntegrityViolationException);
+            return CommandProcessingResult.empty();
+        }catch(final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleFinancialActivityAccountDataIntegrityIssues(command, 
throwable, ee);
             return CommandProcessingResult.empty();
         }
     }
@@ -122,8 +129,12 @@ public class 
FinancialActivityAccountWritePlatformServiceImpl implements Financi
                     .with(changes) //
                     .build();
         } catch (DataIntegrityViolationException 
dataIntegrityViolationException) {
-            handleFinancialActivityAccountDataIntegrityIssues(command, 
dataIntegrityViolationException);
+            handleFinancialActivityAccountDataIntegrityIssues(command, 
dataIntegrityViolationException.getMostSpecificCause(), 
dataIntegrityViolationException);
             return CommandProcessingResult.empty();
+        }catch(final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleFinancialActivityAccountDataIntegrityIssues(command, 
throwable, ee);
+               return CommandProcessingResult.empty();
         }
     }
 
@@ -138,8 +149,7 @@ public class 
FinancialActivityAccountWritePlatformServiceImpl implements Financi
                 .build();
     }
 
-    private void handleFinancialActivityAccountDataIntegrityIssues(final 
JsonCommand command, final DataIntegrityViolationException dve) {
-        final Throwable realCause = dve.getMostSpecificCause();
+    private void handleFinancialActivityAccountDataIntegrityIssues(final 
JsonCommand command, final Throwable realCause, final Exception dve) {
         if (realCause.getMessage().contains("financial_activity_type")) {
             final Integer financialActivityId = command
                     
.integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue());

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccount.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccount.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccount.java
index 5ed1ab9..b68cd4a 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccount.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccount.java
@@ -37,11 +37,11 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.accounting.glaccount.api.GLAccountJsonInputParams;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "acc_gl_account", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "gl_code" }, name = "acc_gl_code") })
-public class GLAccount extends AbstractPersistable<Long> {
+public class GLAccount extends AbstractPersistableCustom<Long> {
 
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")
@@ -52,7 +52,7 @@ public class GLAccount extends AbstractPersistable<Long> {
 
     @OneToMany(fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")
-    private final List<GLAccount> children = new LinkedList<>();
+    private List<GLAccount> children = new LinkedList<>();
 
     @Column(name = "name", nullable = false, length = 45)
     private String name;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntryRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntryRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntryRepository.java
index 120b03e..c280f89 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntryRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/domain/JournalEntryRepository.java
@@ -29,24 +29,24 @@ import org.springframework.data.repository.query.Param;
 public interface JournalEntryRepository extends JpaRepository<JournalEntry, 
Long>, JpaSpecificationExecutor<JournalEntry>,
         JournalEntryRepositoryCustom {
 
-    @Query("from JournalEntry journalEntry where journalEntry.transactionId= 
:transactionId and journalEntry.reversed is false and journalEntry.manualEntry 
is true")
+    @Query("select journalEntry from JournalEntry journalEntry where 
journalEntry.transactionId= :transactionId and journalEntry.reversed=false and 
journalEntry.manualEntry=true")
     List<JournalEntry> 
findUnReversedManualJournalEntriesByTransactionId(@Param("transactionId") 
String transactionId);
 
     @Query("select DISTINCT j.transactionId from JournalEntry j where 
j.transactionId not in (select DISTINCT je.transactionId from JournalEntry je 
where je.glAccount.id = :contraId)")
     List<String> findNonContraTansactionIds(@Param("contraId") Long contraId);
 
-    @Query("select DISTINCT j.transactionId from JournalEntry j where 
j.office.id = :officeId and j.glAccount.id = :contraId and j.reversed is false 
and j.transactionId not in (select DISTINCT 
je.reversalJournalEntry.transactionId from JournalEntry je where je.reversed is 
true)")
+    @Query("select DISTINCT j.transactionId from JournalEntry j where 
j.office.id = :officeId and j.glAccount.id = :contraId and j.reversed=false and 
j.transactionId not in (select DISTINCT je.reversalJournalEntry.transactionId 
from JournalEntry je where je.reversed=true)")
     List<String> findNonReversedContraTansactionIds(@Param("contraId") Long 
contraId, @Param("officeId") Long officeId);
     
-    @Query("from JournalEntry journalEntry where journalEntry.entityId= 
:entityId and journalEntry.entityType = :entityType")    
+    @Query("select journalEntry from JournalEntry journalEntry where 
journalEntry.entityId= :entityId and journalEntry.entityType = :entityType")    
     List<JournalEntry> 
findProvisioningJournalEntriesByEntityId(@Param("entityId") Long entityId, 
@Param("entityType") Integer entityType) ;
 
-    @Query("from JournalEntry journalEntry where journalEntry.transactionId= 
:transactionId and journalEntry.reversed is false and journalEntry.entityType = 
:entityType")
+    @Query("select journalEntry from JournalEntry journalEntry where 
journalEntry.transactionId= :transactionId and journalEntry.reversed=false and 
journalEntry.entityType = :entityType")
     List<JournalEntry> findJournalEntries(@Param("transactionId") String 
transactionId, @Param("entityType") Integer entityType);
 
-    @Query("from JournalEntry journalEntry where glAccount.id= :accountId and 
transactionId= :transactionId and transactionDate= :transactionDate"
+    /*@Query("select journalEntry from JournalEntry journalEntry where 
glAccount.id= :accountId and transactionId= :transactionId and transactionDate= 
:transactionDate"
             + " and type= :journalEntryType and entityType=1 and entityId= 
:loanId and loanTransaction.id= :loanTransactionId")
     JournalEntry findLOANJournalEntryWith(@Param("accountId") Long accountId, 
@Param("transactionId") String transactionId,
             @Param("transactionDate") Date transactionDate, 
@Param("journalEntryType") Integer journalEntryType,
-            @Param("loanId") Long loanId, @Param("loanTransactionId") Long 
loanTransactionId);
+            @Param("loanId") Long loanId, @Param("loanTransactionId") Long 
loanTransactionId);*/
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMapping.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMapping.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMapping.java
index 4c9bbaf..78a5b4d 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMapping.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMapping.java
@@ -20,41 +20,40 @@ package 
org.apache.fineract.accounting.producttoaccountmapping.domain;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
-import javax.persistence.FetchType;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 import javax.persistence.UniqueConstraint;
 
 import org.apache.fineract.accounting.glaccount.domain.GLAccount;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.apache.fineract.portfolio.charge.domain.Charge;
 import org.apache.fineract.portfolio.paymenttype.domain.PaymentType;
-import org.springframework.data.jpa.domain.AbstractPersistable;
 
 @Entity
 @Table(name = "acc_product_mapping", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "product_id", "product_type",
         "financial_account_type", "payment_type" }, name = "financial_action") 
})
-public class ProductToGLAccountMapping extends AbstractPersistable<Long> {
+public class ProductToGLAccountMapping extends AbstractPersistableCustom<Long> 
{
 
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne(optional=true)
     @JoinColumn(name = "gl_account_id")
     private GLAccount glAccount;
 
-    @Column(name = "product_id", nullable = false)
+    @Column(name = "product_id", nullable = true)
     private Long productId;
 
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne
     @JoinColumn(name = "payment_type", nullable = true)
     private PaymentType paymentType;
 
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne
     @JoinColumn(name = "charge_id", nullable = true)
     private Charge charge;
 
-    @Column(name = "product_type", nullable = false)
+    @Column(name = "product_type", nullable = true)
     private int productType;
 
-    @Column(name = "financial_account_type", nullable = false)
+    @Column(name = "financial_account_type", nullable = true)
     private int financialAccountType;
 
     public static ProductToGLAccountMapping createNew(final GLAccount 
glAccount, final Long productId, final int productType,

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java
index 230de00..0882c7b 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java
@@ -34,22 +34,22 @@ public interface ProductToGLAccountMappingRepository 
extends JpaRepository<Produ
     ProductToGLAccountMapping 
findByProductIdAndProductTypeAndFinancialAccountTypeAndChargeId(Long productId, 
int productType,
             int financialAccountType, Long chargeId);
 
-    @Query("from ProductToGLAccountMapping mapping where mapping.productId 
=:productId and mapping.productType =:productType and 
mapping.financialAccountType=:financialAccountType and mapping.paymentType is 
NULL and mapping.charge is NULL")
+    @Query("select mapping from ProductToGLAccountMapping mapping where 
mapping.productId =:productId and mapping.productType =:productType and 
mapping.financialAccountType=:financialAccountType and mapping.paymentType is 
NULL and mapping.charge is NULL")
     ProductToGLAccountMapping 
findCoreProductToFinAccountMapping(@Param("productId") Long productId, 
@Param("productType") int productType,
             @Param("financialAccountType") int financialAccountType);
 
     /*** The financial Account Type for a fund source will always be an asset 
(1) ***/
-    @Query("from ProductToGLAccountMapping mapping where mapping.productId 
=:productId and mapping.productType =:productType and 
mapping.financialAccountType=1 and mapping.paymentType is not NULL")
+    @Query("select mapping from ProductToGLAccountMapping mapping where 
mapping.productId =:productId and mapping.productType =:productType and 
mapping.financialAccountType=1 and mapping.paymentType is not NULL")
     List<ProductToGLAccountMapping> 
findAllPaymentTypeToFundSourceMappings(@Param("productId") Long productId,
             @Param("productType") int productType);
 
     /*** The financial Account Type for income from interest will always be 4 
***/
-    @Query("from ProductToGLAccountMapping mapping where mapping.productId 
=:productId and mapping.productType =:productType and 
mapping.financialAccountType=4 and mapping.charge is not NULL")
+    @Query("select mapping from ProductToGLAccountMapping mapping where 
mapping.productId =:productId and mapping.productType =:productType and 
mapping.financialAccountType=4 and mapping.charge is not NULL")
     List<ProductToGLAccountMapping> 
findAllFeeToIncomeAccountMappings(@Param("productId") Long productId,
             @Param("productType") int productType);
 
     /*** The financial Account Type for income from interest will always be 5 
***/
-    @Query("from ProductToGLAccountMapping mapping where mapping.productId 
=:productId and mapping.productType =:productType and 
mapping.financialAccountType=5 and mapping.charge is not NULL")
+    @Query("select mapping from ProductToGLAccountMapping mapping where 
mapping.productId =:productId and mapping.productType =:productType and 
mapping.financialAccountType=5 and mapping.charge is not NULL")
     List<ProductToGLAccountMapping> 
findAllPenaltyToIncomeAccountMappings(@Param("productId") Long productId,
             @Param("productType") int productType);
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/LoanProductProvisioningEntry.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/LoanProductProvisioningEntry.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/LoanProductProvisioningEntry.java
index 49ea228..42db8d8 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/LoanProductProvisioningEntry.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/LoanProductProvisioningEntry.java
@@ -27,14 +27,14 @@ import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 import org.apache.fineract.accounting.glaccount.domain.GLAccount;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.apache.fineract.organisation.office.domain.Office;
 import 
org.apache.fineract.organisation.provisioning.domain.ProvisioningCategory;
 import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
-import org.springframework.data.jpa.domain.AbstractPersistable;
 
 @Entity
 @Table(name = "m_loanproduct_provisioning_entry")
-public class LoanProductProvisioningEntry extends AbstractPersistable<Long> {
+public class LoanProductProvisioningEntry extends 
AbstractPersistableCustom<Long> {
 
     @ManyToOne(optional = false)
     @JoinColumn(name = "history_id", referencedColumnName = "id", nullable = 
false)

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java
index 5b56507..920c7c7 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntry.java
@@ -35,17 +35,17 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
 import org.apache.fineract.useradministration.domain.AppUser;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_provisioning_history")
-public class ProvisioningEntry extends AbstractPersistable<Long> {
+public class ProvisioningEntry extends AbstractPersistableCustom<Long> {
 
     @Column(name = "journal_entry_created")
     private Boolean isJournalEntryCreated;
     
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "entry", orphanRemoval = 
true, fetch=FetchType.EAGER)
-    Set<LoanProductProvisioningEntry> provisioningEntries = new HashSet<>();
+    private Set<LoanProductProvisioningEntry> provisioningEntries = new 
HashSet<>();
     
     @OneToOne
     @JoinColumn(name = "createdby_id")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java
index 5abed20..50c7ad2 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/domain/ProvisioningEntryRepository.java
@@ -27,9 +27,10 @@ import org.springframework.data.repository.query.Param;
 
 public interface ProvisioningEntryRepository extends 
JpaRepository<ProvisioningEntry, Long>, 
JpaSpecificationExecutor<ProvisioningEntry> {
 
-    @Query("select entry from ProvisioningEntry entry where entry.createdDate 
= :createdDate")
+       //OPENJPA throws error if we use entry 
+    @Query("select entry1 from ProvisioningEntry entry1 where 
entry1.createdDate = :createdDate")
     ProvisioningEntry findByProvisioningEntryDate(@Param("createdDate") Date 
createdDate);
     
-    @Query("select entry from ProvisioningEntry entry where entry.createdDate 
= (select max(entry1.createdDate) from ProvisioningEntry entry1 where 
entry1.isJournalEntryCreated='1')")
+    @Query("select entry1 from ProvisioningEntry entry1 where 
entry1.createdDate = (select max(entry2.createdDate) from ProvisioningEntry 
entry2 where entry2.isJournalEntryCreated=true)")
     ProvisioningEntry findExistingProvisioningEntryWithJournalEntries() ;
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java
index a603722..0b09b10 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java
@@ -41,11 +41,11 @@ import 
org.apache.fineract.accounting.journalentry.domain.JournalEntryType;
 import org.apache.fineract.accounting.rule.api.AccountingRuleJsonInputParams;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "acc_accounting_rule", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "name" }, name = 
"accounting_rule_name_unique") })
-public class AccountingRule extends AbstractPersistable<Long> {
+public class AccountingRule extends AbstractPersistableCustom<Long> {
 
     @Column(name = "name", nullable = false, length = 500)
     private String name;
@@ -69,7 +69,7 @@ public class AccountingRule extends AbstractPersistable<Long> 
{
     private Boolean systemDefined;
 
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "accountingRule", 
orphanRemoval = true, fetch=FetchType.EAGER)
-    private final List<AccountingTagRule> accountingTagRules = new 
ArrayList<>();
+    private List<AccountingTagRule> accountingTagRules = new ArrayList<>();
 
     @Column(name = "allow_multiple_credits", nullable = false)
     private boolean allowMultipleCreditEntries;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRuleRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRuleRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRuleRepository.java
index 89e67c2..17d807c 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRuleRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRuleRepository.java
@@ -25,6 +25,6 @@ import org.springframework.data.repository.query.Param;
 
 public interface AccountingRuleRepository extends 
JpaRepository<AccountingRule, Long>, JpaSpecificationExecutor<AccountingRule> {
 
-    @Query("from AccountingRule accountingRule where accountingRule.office is 
null or accountingRule.office.id =:officeId")
+    @Query("select accountingRule from AccountingRule accountingRule where 
accountingRule.office is null or accountingRule.office.id =:officeId")
     AccountingRule getAccountingRuleByOfficeId(@Param("officeId") Long 
officeId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java
index f47e977..16f138d 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java
@@ -27,11 +27,11 @@ import javax.persistence.UniqueConstraint;
 
 import org.apache.fineract.accounting.journalentry.domain.JournalEntryType;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "acc_rule_tags", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "acc_rule_id", "tag_id", "acc_type_enum" }, 
name = "UNIQUE_ACCOUNT_RULE_TAGS") })
-public class AccountingTagRule extends AbstractPersistable<Long> {
+public class AccountingTagRule extends AbstractPersistableCustom<Long> {
 
     @ManyToOne
     @JoinColumn(name = "acc_rule_id", nullable = false)

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java
 
b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java
index 65d166d..76b373c 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java
@@ -31,6 +31,7 @@ import 
org.apache.fineract.infrastructure.core.exceptionmapper.PlatformResourceN
 import 
org.apache.fineract.infrastructure.core.exceptionmapper.UnsupportedParameterExceptionMapper;
 import 
org.apache.fineract.portfolio.loanaccount.exception.MultiDisbursementDataRequiredException;
 import 
org.apache.fineract.portfolio.loanproduct.exception.LinkedAccountRequiredException;
+import org.springframework.dao.NonTransientDataAccessException;
 import org.springframework.transaction.TransactionException;
 
 import com.google.gson.Gson;
@@ -120,6 +121,8 @@ public class ErrorHandler extends RuntimeException {
             final String errorBody = 
jsonHelper.toJson(mapper.toResponse((PlatformInternalServerException) 
exception).getEntity());
 
             return new ErrorInfo(500, 5001, errorBody);
+        }else if(exception instanceof NonTransientDataAccessException) {
+               return new ErrorInfo(400, 4001, "{\"Exception\": " + 
exception.getMessage()+"}");
         }
 
         return new ErrorInfo(500, 9999, "{\"Exception\": " + 
exception.toString() + "}");

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
index d7aadd8..0eec7da 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java
@@ -35,6 +35,7 @@ import org.apache.fineract.batch.exception.ErrorHandler;
 import org.apache.fineract.batch.exception.ErrorInfo;
 import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.NonTransientDataAccessException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionException;
 import org.springframework.transaction.TransactionStatus;
@@ -216,7 +217,22 @@ public class BatchApiServiceImpl implements 
BatchApiService {
             errResponseList.add(errResponse);
 
             return errResponseList;
+        }catch (final NonTransientDataAccessException ex) {
+                ErrorInfo e = ErrorHandler.handler(ex);
+             BatchResponse errResponse = new BatchResponse();
+             errResponse.setStatusCode(e.getStatusCode());
+
+             for (BatchResponse res : checkList) {
+                 if (!res.getStatusCode().equals(200)) {
+                     errResponse.setBody("Transaction is being rolled back. 
First erroneous request: \n" + new Gson().toJson(res));
+                     break;
+                 }
+             }
+             checkList.clear();
+             List<BatchResponse> errResponseList = new ArrayList<>();
+             errResponseList.add(errResponse);
+
+             return errResponseList;
         }
-
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
 
b/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
index a859e8e..a19d22c 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
@@ -32,11 +32,11 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.useradministration.domain.AppUser;
 import org.joda.time.DateTime;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_portfolio_command_source")
-public class CommandSource extends AbstractPersistable<Long> {
+public class CommandSource extends AbstractPersistableCustom<Long> {
 
     @Column(name = "action_name", nullable = true, length = 100)
     private String actionName;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormat.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormat.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormat.java
index 064c1a6..4ff34cc 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormat.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormat.java
@@ -25,16 +25,16 @@ import javax.persistence.UniqueConstraint;
 
 import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatEnumerations.AccountNumberPrefixType;
 import 
org.apache.fineract.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = AccountNumberFormatConstants.ACCOUNT_NUMBER_FORMAT_TABLE_NAME, 
uniqueConstraints = { @UniqueConstraint(columnNames = { 
AccountNumberFormatConstants.ACCOUNT_TYPE_ENUM_COLUMN_NAME }, name = 
AccountNumberFormatConstants.ACCOUNT_TYPE_UNIQUE_CONSTRAINT_NAME) })
-public class AccountNumberFormat extends AbstractPersistable<Long> {
+public class AccountNumberFormat extends AbstractPersistableCustom<Long> {
 
     @Column(name = AccountNumberFormatConstants.ACCOUNT_TYPE_ENUM_COLUMN_NAME, 
nullable = false)
     private Integer accountTypeEnum;
 
-    @Column(name = AccountNumberFormatConstants.PREFIX_TYPE_ENUM_COLUMN_NAME, 
nullable = false)
+    @Column(name = AccountNumberFormatConstants.PREFIX_TYPE_ENUM_COLUMN_NAME, 
nullable = true)
     private Integer prefixEnum;
 
     protected AccountNumberFormat() {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormatRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormatRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormatRepository.java
index 3557bad..12396ab 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormatRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/domain/AccountNumberFormatRepository.java
@@ -26,7 +26,7 @@ import org.springframework.data.repository.query.Param;
 public interface AccountNumberFormatRepository extends 
JpaRepository<AccountNumberFormat, Long>,
         JpaSpecificationExecutor<AccountNumberFormat> {
 
-    public static final String FIND_ACCOUNT_NUMBER_FORMAT_FOR_ENTITY = "from  
AccountNumberFormat anf where anf.accountTypeEnum = :accountTypeEnum";
+    public static final String FIND_ACCOUNT_NUMBER_FORMAT_FOR_ENTITY = "select 
anf from  AccountNumberFormat anf where anf.accountTypeEnum = :accountTypeEnum";
 
     @Query(FIND_ACCOUNT_NUMBER_FORMAT_FOR_ENTITY)
     AccountNumberFormat findOneByAccountTypeEnum(@Param("accountTypeEnum") 
Integer accountTypeEnum);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
index b4afef2..31fe1b2 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
@@ -21,11 +21,14 @@ package 
org.apache.fineract.infrastructure.accountnumberformat.service;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import 
org.apache.fineract.infrastructure.accountnumberformat.data.AccountNumberFormatDataValidator;
 import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat;
+import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatEnumerations.AccountNumberPrefixType;
 import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
 import 
org.apache.fineract.infrastructure.accountnumberformat.domain.EntityAccountType;
-import 
org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatEnumerations.AccountNumberPrefixType;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
@@ -74,8 +77,12 @@ public class 
AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements
                     .withEntityId(accountNumberFormat.getId()) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), 
dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleDataIntegrityIssues(command, throwable, ee);
+               return CommandProcessingResult.empty();
         }
     }
 
@@ -110,8 +117,12 @@ public class 
AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements
                     .with(actualChanges) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), 
dve);
             return CommandProcessingResult.empty();
+        } catch (final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleDataIntegrityIssues(command, throwable, ee);
+               return CommandProcessingResult.empty();
         }
     }
 
@@ -126,13 +137,12 @@ public class 
AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements
                 .build();
     }
 
+        
     /*
      * Guaranteed to throw an exception no matter what the data integrity issue
      * is.
      */
-    private void handleDataIntegrityIssues(final JsonCommand command, final 
DataIntegrityViolationException dve) {
-
-        final Throwable realCause = dve.getMostSpecificCause();
+    private void handleDataIntegrityIssues(final JsonCommand command, final 
Throwable realCause, final Exception dve) {
         if 
(realCause.getMessage().contains(AccountNumberFormatConstants.ACCOUNT_TYPE_UNIQUE_CONSTRAINT_NAME))
 {
 
             final Integer accountTypeId = 
command.integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.accountTypeParamName);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/domain/PlatformCache.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/domain/PlatformCache.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/domain/PlatformCache.java
index 9af367b..9ccfa2d 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/domain/PlatformCache.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/domain/PlatformCache.java
@@ -22,11 +22,11 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Table;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "c_cache")
-public class PlatformCache extends AbstractPersistable<Long> {
+public class PlatformCache extends AbstractPersistableCustom<Long> {
 
     @Column(name = "cache_type_enum")
     private Integer cacheType;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/Code.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/Code.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/Code.java
index 22042a3..82fafb2 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/Code.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/Code.java
@@ -33,17 +33,17 @@ import javax.persistence.UniqueConstraint;
 import org.apache.commons.lang.StringUtils;
 import 
org.apache.fineract.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_code", uniqueConstraints = { @UniqueConstraint(columnNames = 
{ "code_name" }, name = "code_name") })
-public class Code extends AbstractPersistable<Long> {
+public class Code extends AbstractPersistableCustom<Long> {
 
     @Column(name = "code_name", length = 100)
     private String name;
 
     @Column(name = "is_system_defined")
-    private final boolean systemDefined;
+    private boolean systemDefined;
 
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = 
"code", orphanRemoval = true)
     private Set<CodeValue> values;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
index 5045c67..8ee1ac8 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValue.java
@@ -32,11 +32,11 @@ import org.apache.commons.lang.StringUtils;
 import 
org.apache.fineract.infrastructure.codes.CodeConstants.CODEVALUE_JSON_INPUT_PARAMS;
 import org.apache.fineract.infrastructure.codes.data.CodeValueData;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_code_value", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "code_id", "code_value" }, name = 
"code_value_duplicate") })
-public class CodeValue extends AbstractPersistable<Long> {
+public class CodeValue extends AbstractPersistableCustom<Long> {
 
     @Column(name = "code_value", length = 100)
     private String label;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java
index 3926d18..672fc5e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java
@@ -20,6 +20,9 @@ package org.apache.fineract.infrastructure.codes.service;
 
 import java.util.Map;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.codes.domain.Code;
 import org.apache.fineract.infrastructure.codes.domain.CodeRepository;
 import 
org.apache.fineract.infrastructure.codes.exception.CodeNotFoundException;
@@ -70,8 +73,12 @@ public class CodeWritePlatformServiceJpaRepositoryImpl 
implements CodeWritePlatf
 
             return new 
CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(code.getId()).build();
         } catch (final DataIntegrityViolationException dve) {
-            handleCodeDataIntegrityIssues(command, dve);
+            handleCodeDataIntegrityIssues(command, dve.getMostSpecificCause(), 
dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleCodeDataIntegrityIssues(command, throwable, ee);
+               return CommandProcessingResult.empty();
         }
     }
 
@@ -98,8 +105,12 @@ public class CodeWritePlatformServiceJpaRepositoryImpl 
implements CodeWritePlatf
                     .with(changes) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleCodeDataIntegrityIssues(command, dve);
-            return null;
+            handleCodeDataIntegrityIssues(command, dve.getMostSpecificCause(), 
dve);
+            return CommandProcessingResult.empty();
+        }catch (final PersistenceException ee) {
+               Throwable throwable = 
ExceptionUtils.getRootCause(ee.getCause()) ;
+               handleCodeDataIntegrityIssues(command, throwable, ee);
+               return CommandProcessingResult.empty();
         }
     }
 
@@ -133,8 +144,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl 
implements CodeWritePlatf
      * Guaranteed to throw an exception no matter what the data integrity issue
      * is.
      */
-    private void handleCodeDataIntegrityIssues(final JsonCommand command, 
final DataIntegrityViolationException dve) {
-        final Throwable realCause = dve.getMostSpecificCause();
+    private void handleCodeDataIntegrityIssues(final JsonCommand command, 
final Throwable realCause, final Exception dve) {
         if (realCause.getMessage().contains("code_name")) {
             final String name = command.stringValueOfParameterNamed("name");
             throw new 
PlatformDataIntegrityException("error.msg.code.duplicate.name", "A code with 
name '" + name + "' already exists",

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalService.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalService.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalService.java
index 5bbd0ed..23008be 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalService.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalService.java
@@ -23,11 +23,11 @@ import javax.persistence.Table;
 import javax.persistence.UniqueConstraint;
 
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "c_external_service", uniqueConstraints = { 
@UniqueConstraint(columnNames = { "name" }, name = "name_UNIQUE") })
-public class ExternalService extends AbstractPersistable<Long> {
+public class ExternalService extends AbstractPersistableCustom<Long> {
 
     @Column(name = "name", length = 50)
     private String name;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
index c9fc332..4e60bad 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicePropertiesPK.java
@@ -23,6 +23,9 @@ import java.io.Serializable;
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
 
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
 @Embeddable
 public class ExternalServicePropertiesPK implements Serializable {
 
@@ -48,5 +51,30 @@ public class ExternalServicePropertiesPK implements 
Serializable {
     public Long getExternalService() {
         return externalServiceId;
     }
+    
+    @Override 
+       public boolean equals(Object obj) {
+               if (obj == null) {
+                       return false;
+               }
+               if (obj == this) {
+                       return true;
+               }
+               if (obj.getClass() != getClass()) {
+                       return false;
+               }
+               final ExternalServicePropertiesPK rhs = 
(ExternalServicePropertiesPK) obj;
+               return new EqualsBuilder() //
+                               .append(this.externalServiceId, 
rhs.externalServiceId) //
+                               .append(this.name, rhs.name) //
+                               .isEquals();
+       }
 
+    @Override 
+    public int hashCode() {
+        return new HashCodeBuilder(17, 37) //
+                .append(this.externalServiceId) //
+                .append(this.name) //
+                .toHashCode();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesProperties.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesProperties.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesProperties.java
index 3504056..6e36b3d 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesProperties.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesProperties.java
@@ -52,7 +52,6 @@ public class ExternalServicesProperties {
         this.value = value;
 
     }
-
     public static ExternalServicesProperties fromJson(final ExternalService 
externalService, final JsonCommand command) {
         final String name = 
command.stringValueOfParameterNamed(EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.NAME.getValue());
         final String value = 
command.stringValueOfParameterNamed(EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.VALUE.getValue());
@@ -80,5 +79,4 @@ public class ExternalServicesProperties {
     public ExternalServicesPropertiesData toData() {
         return new 
ExternalServicesPropertiesData(this.externalServicePropertiesPK.getName(), 
this.value);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
index 98a0e5c..6db62a3 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepository.java
@@ -20,9 +20,12 @@ package 
org.apache.fineract.infrastructure.configuration.domain;
 
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 
 public interface ExternalServicesPropertiesRepository extends 
JpaRepository<ExternalServicesProperties, ExternalServicePropertiesPK>,
         JpaSpecificationExecutor<ExternalServicesProperties> {
 
-    ExternalServicesProperties 
findOneByExternalServicePropertiesPK(ExternalServicePropertiesPK 
externalServicesProptiesPK);
+       @Query("SELECT ep from ExternalServicesProperties ep where 
ep.externalServicePropertiesPK.name=:name and 
ep.externalServicePropertiesPK.externalServiceId=:externalServiceId")
+    ExternalServicesProperties 
findOneByExternalServicePropertiesPK(@Param("name") String name, 
@Param("externalServiceId") Long externalServiceId);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
index 92201f4..76b038e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/ExternalServicesPropertiesRepositoryWrapper.java
@@ -34,7 +34,7 @@ public class ExternalServicesPropertiesRepositoryWrapper {
 
     public ExternalServicesProperties findOneByIdAndName(Long id, String name, 
String externalServiceName) {
         final ExternalServicesProperties externalServicesProperties = 
this.repository
-                .findOneByExternalServicePropertiesPK(new 
ExternalServicePropertiesPK(id, name));
+                .findOneByExternalServicePropertiesPK(name,id);
         if (externalServicesProperties == null) throw new 
ExternalServiceConfigurationNotFoundException(externalServiceName, name);
         return externalServicesProperties;
     }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/GlobalConfigurationProperty.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/GlobalConfigurationProperty.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/GlobalConfigurationProperty.java
index 40d681b..10f4e85 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/GlobalConfigurationProperty.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/domain/GlobalConfigurationProperty.java
@@ -30,14 +30,14 @@ import 
org.apache.fineract.infrastructure.configuration.data.GlobalConfiguration
 import 
org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import 
org.apache.fineract.infrastructure.security.exception.ForcePasswordResetException;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "c_configuration")
-public class GlobalConfigurationProperty extends AbstractPersistable<Long> {
+public class GlobalConfigurationProperty extends 
AbstractPersistableCustom<Long> {
 
     @Column(name = "name", nullable = false)
-    private final String name;
+    private String name;
 
     @Column(name = "enabled", nullable = false)
     private boolean enabled;
@@ -49,7 +49,7 @@ public class GlobalConfigurationProperty extends 
AbstractPersistable<Long> {
     private Date dateValue;
 
     @Column(name = "description", nullable = true)
-    private final String description;
+    private String description;
 
     @Column(name = "is_trap_door", nullable = false)
     private boolean isTrapDoor;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java
index 9a669a0..75a7ae0 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/ApiParameterError.java
@@ -18,7 +18,9 @@
  */
 package org.apache.fineract.infrastructure.core.data;
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 public class ApiParameterError {
@@ -57,6 +59,8 @@ public class ApiParameterError {
      */
     private List<ApiErrorMessageArg> args = new ArrayList<>();
 
+    private final transient SimpleDateFormat dateFormatter = new 
SimpleDateFormat("yyyy-MM-dd");
+
     public static ApiParameterError generalError(final String 
globalisationMessageCode, final String defaultUserMessage,
             final Object... defaultUserMessageArgs) {
         return new ApiParameterError(globalisationMessageCode, 
defaultUserMessage, defaultUserMessageArgs);
@@ -86,7 +90,12 @@ public class ApiParameterError {
         final List<ApiErrorMessageArg> messageArgs = new ArrayList<>();
         if (defaultUserMessageArgs != null) {
             for (final Object object : defaultUserMessageArgs) {
-                messageArgs.add(ApiErrorMessageArg.from(object));
+                if(object instanceof Date){
+                    final String formattedDate = dateFormatter.format(object);
+                    messageArgs.add(ApiErrorMessageArg.from(formattedDate));
+                } else {
+                    messageArgs.add(ApiErrorMessageArg.from(object));
+                }
             }
         }
         this.args = messageArgs;

Reply via email to