You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ra...@apache.org on 2016/09/21 08:44:27 UTC

[4/4] incubator-fineract git commit: Loading child entites lazy

Loading child entites lazy


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

Branch: refs/heads/develop
Commit: 025ff9c707c8f68b226c1af523f3f42a742a8a9a
Parents: 19c0def
Author: Nazeer Hussain Shaik <na...@confluxtechnologies.com>
Authored: Mon Sep 19 14:03:37 2016 +0530
Committer: Nazeer Hussain Shaik <na...@confluxtechnologies.com>
Committed: Mon Sep 19 14:03:37 2016 +0530

----------------------------------------------------------------------
 ...reWritePlatformServiceJpaRepositoryImpl.java |  15 +-
 .../service/AccountingProcessorHelper.java      |  12 +-
 ...nalEntryRunningBalanceUpdateServiceImpl.java |  14 +-
 ...ryWritePlatformServiceJpaRepositoryImpl.java |  17 +-
 ...esWritePlatformServiceJpaRepositoryImpl.java |  10 +-
 ...leWritePlatformServiceJpaRepositoryImpl.java |  15 +-
 .../hooks/processor/TwilioHookProcessor.java    |  27 +--
 ...ayWritePlatformServiceJpaRepositoryImpl.java |  12 +-
 .../organisation/office/domain/Office.java      |   6 +-
 .../office/domain/OfficeRepositoryWrapper.java  |  17 +-
 ...ceWritePlatformServiceJpaRepositoryImpl.java |  28 ++-
 ...ffWritePlatformServiceJpaRepositoryImpl.java |  17 +-
 .../TellerWritePlatformServiceJpaImpl.java      |  21 +--
 .../domain/AccountTransferDetailAssembler.java  |  20 +-
 .../AddressWritePlatformServiceImpl.java        |  10 +-
 ...arWritePlatformServiceJpaRepositoryImpl.java |  10 +-
 .../portfolio/client/domain/Client.java         |  94 +++++-----
 .../portfolio/client/domain/ClientAddress.java  |   1 -
 .../client/domain/ClientRepository.java         |   2 +-
 .../client/domain/ClientRepositoryWrapper.java  |  21 ++-
 ...ntWritePlatformServiceJpaRepositoryImpl.java |  74 ++++----
 .../CollateralReadPlatformServiceImpl.java      |  13 +-
 ...alWritePlatformServiceJpaRepositoryImpl.java |  28 +--
 ...esWritePlatformServiceJpaRepositoryImpl.java |  43 ++---
 .../portfolio/loanaccount/domain/Loan.java      | 100 +++++-----
 .../domain/LoanAccountDomainServiceJpa.java     |  16 +-
 .../domain/LoanRepositoryWrapper.java           | 181 ++++++++++++++++++-
 .../GuarantorReadPlatformServiceImpl.java       |  13 +-
 ...rWritePlatformServiceJpaRepositoryIImpl.java |   6 +-
 .../domain/AbstractLoanScheduleGenerator.java   |   3 +-
 .../service/LoanScheduleAssembler.java          |   8 +-
 ...nScheduleCalculationPlatformServiceImpl.java |   4 +-
 .../LoanScheduleWritePlatformServiceImpl.java   |   5 +-
 ...escheduleRequestReadPlatformServiceImpl.java |  21 +--
 ...scheduleRequestWritePlatformServiceImpl.java |  12 +-
 .../LoanAccrualWritePlatformServiceImpl.java    |  12 +-
 ...onWritePlatformServiceJpaRepositoryImpl.java |  49 +++--
 .../loanaccount/service/LoanAssembler.java      |   4 +-
 .../service/LoanChargeAssembler.java            |   2 +-
 .../service/LoanReadPlatformServiceImpl.java    |  37 ++--
 .../loanaccount/service/LoanUtilService.java    |   5 +-
 .../service/LoanWritePlatformService.java       |   9 +-
 ...anWritePlatformServiceJpaRepositoryImpl.java | 102 ++++++-----
 ...ctWritePlatformServiceJpaRepositoryImpl.java |  11 +-
 ...ngWritePlatformServiceJpaRepositoryImpl.java |  16 +-
 ...teWritePlatformServiceJpaRepositoryImpl.java |  15 +-
 .../savings/data/SavingsAccountDataDTO.java     |  11 +-
 .../savings/domain/DepositAccountAssembler.java |   3 +-
 .../savings/domain/RecurringDepositAccount.java |  24 +--
 .../savings/domain/SavingsAccount.java          |  30 ++-
 .../savings/domain/SavingsAccountAssembler.java |   4 +-
 .../domain/SavingsAccountRepository.java        |   1 +
 .../domain/SavingsAccountRepositoryWrapper.java |  58 +++++-
 .../savings/domain/SavingsAccountSummary.java   |   3 +-
 ...SavingsAccountTransactionSummaryWrapper.java |  24 +--
 ...ntWritePlatformServiceJpaRepositoryImpl.java |  66 +++----
 .../SavingsAccountWritePlatformService.java     |   8 +-
 ...ntWritePlatformServiceJpaRepositoryImpl.java |  73 ++++----
 .../service/SavingsSchedularServiceImpl.java    |  10 +-
 ...eneficiariesTPTWritePlatformServiceImpl.java |  21 +--
 ...erWritePlatformServiceJpaRepositoryImpl.java |  76 ++++----
 .../fineract/spm/api/ScorecardApiResource.java  |  45 ++---
 ...erWritePlatformServiceJpaRepositoryImpl.java |  28 ++-
 63 files changed, 885 insertions(+), 758 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java
index 4c305df..7b00ac8 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java
@@ -28,16 +28,15 @@ import org.apache.fineract.accounting.closure.domain.GLClosureRepository;
 import org.apache.fineract.accounting.closure.exception.GLClosureDuplicateException;
 import org.apache.fineract.accounting.closure.exception.GLClosureInvalidDeleteException;
 import org.apache.fineract.accounting.closure.exception.GLClosureInvalidException;
-import org.apache.fineract.accounting.closure.exception.GLClosureNotFoundException;
 import org.apache.fineract.accounting.closure.exception.GLClosureInvalidException.GL_CLOSURE_INVALID_REASON;
+import org.apache.fineract.accounting.closure.exception.GLClosureNotFoundException;
 import org.apache.fineract.accounting.closure.serialization.GLClosureCommandFromApiJsonDeserializer;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.joda.time.LocalDate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,14 +51,14 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure
     private final static Logger logger = LoggerFactory.getLogger(GLClosureWritePlatformServiceJpaRepositoryImpl.class);
 
     private final GLClosureRepository glClosureRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final GLClosureCommandFromApiJsonDeserializer fromApiJsonDeserializer;
 
     @Autowired
     public GLClosureWritePlatformServiceJpaRepositoryImpl(final GLClosureRepository glClosureRepository,
-            final OfficeRepository officeRepository, final GLClosureCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
+            final OfficeRepositoryWrapper officeRepositoryWrapper, final GLClosureCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
         this.glClosureRepository = glClosureRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
     }
 
@@ -72,9 +71,7 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure
 
             // check office is valid
             final Long officeId = command.longValueOfParameterNamed(GLClosureJsonInputParams.OFFICE_ID.getValue());
-            final Office office = this.officeRepository.findOne(officeId);
-            if (office == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             // TODO: Get Tenant specific date
             // ensure closure date is not in the future
             final Date todaysDate = new Date();

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java
index fa3e763..aeef6ce 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccountingProcessorHelper.java
@@ -44,9 +44,9 @@ import org.apache.fineract.accounting.journalentry.data.LoanDTO;
 import org.apache.fineract.accounting.journalentry.data.LoanTransactionDTO;
 import org.apache.fineract.accounting.journalentry.data.SavingsDTO;
 import org.apache.fineract.accounting.journalentry.data.SavingsTransactionDTO;
-import org.apache.fineract.accounting.journalentry.data.TaxPaymentDTO;
 import org.apache.fineract.accounting.journalentry.data.SharesDTO;
 import org.apache.fineract.accounting.journalentry.data.SharesTransactionDTO;
+import org.apache.fineract.accounting.journalentry.data.TaxPaymentDTO;
 import org.apache.fineract.accounting.journalentry.domain.JournalEntry;
 import org.apache.fineract.accounting.journalentry.domain.JournalEntryRepository;
 import org.apache.fineract.accounting.journalentry.domain.JournalEntryType;
@@ -60,7 +60,7 @@ import org.apache.fineract.infrastructure.core.data.EnumOptionData;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.organisation.monetary.data.CurrencyData;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.portfolio.account.PortfolioAccountType;
 import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
 import org.apache.fineract.portfolio.client.domain.ClientTransaction;
@@ -90,7 +90,7 @@ public class AccountingProcessorHelper {
     private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository;
     private final GLClosureRepository closureRepository;
     private final GLAccountRepositoryWrapper accountRepositoryWrapper;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final LoanTransactionRepository loanTransactionRepository;
     private final ClientTransactionRepositoryWrapper clientTransactionRepository;
     private final SavingsAccountTransactionRepository savingsAccountTransactionRepository;
@@ -99,7 +99,7 @@ public class AccountingProcessorHelper {
     @Autowired
     public AccountingProcessorHelper(final JournalEntryRepository glJournalEntryRepository,
             final ProductToGLAccountMappingRepository accountMappingRepository, final GLClosureRepository closureRepository,
-            final OfficeRepository officeRepository, final LoanTransactionRepository loanTransactionRepository,
+            final OfficeRepositoryWrapper officeRepositoryWrapper, final LoanTransactionRepository loanTransactionRepository,
             final SavingsAccountTransactionRepository savingsAccountTransactionRepository,
             final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository,
             final AccountTransfersReadPlatformService accountTransfersReadPlatformService,
@@ -108,7 +108,7 @@ public class AccountingProcessorHelper {
         this.glJournalEntryRepository = glJournalEntryRepository;
         this.accountMappingRepository = accountMappingRepository;
         this.closureRepository = closureRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.loanTransactionRepository = loanTransactionRepository;
         this.savingsAccountTransactionRepository = savingsAccountTransactionRepository;
         this.financialActivityAccountRepository = financialActivityAccountRepository;
@@ -539,7 +539,7 @@ public class AccountingProcessorHelper {
     }
 
     public Office getOfficeById(final long officeId) {
-        return this.officeRepository.findOne(officeId);
+        return this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
     }
 
     private void createJournalEntriesForLoan(final Office office, final String currencyCode, final int accountTypeToDebitId,

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
index 4ab8e11..3a539b6 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
@@ -42,9 +42,7 @@ import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
 import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
 import org.apache.fineract.infrastructure.jobs.annotation.CronTarget;
 import org.apache.fineract.infrastructure.jobs.service.JobName;
-import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,7 +58,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
 
     private final JdbcTemplate jdbcTemplate;
 
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
 
     private final JournalEntryDataValidator dataValidator;
 
@@ -89,10 +87,10 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
             + "where je2.id = je.id and je.entry_date = je3.date group by je.id order by je.entry_date DESC " + selectRunningBalanceSqlLimit;
 
     @Autowired
-    public JournalEntryRunningBalanceUpdateServiceImpl(final RoutingDataSource dataSource, final OfficeRepository officeRepository,
+    public JournalEntryRunningBalanceUpdateServiceImpl(final RoutingDataSource dataSource, final OfficeRepositoryWrapper officeRepositoryWrapper,
             final JournalEntryDataValidator dataValidator, final FromJsonHelper fromApiJsonHelper) {
         this.jdbcTemplate = new JdbcTemplate(dataSource);
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.dataValidator = dataValidator;
         this.fromApiJsonHelper = fromApiJsonHelper;
     }
@@ -120,9 +118,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
         if (officeId == null) {
             updateRunningBalance();
         } else {
-            final Office office = this.officeRepository.findOne(officeId);
-            if (office == null) { throw new OfficeNotFoundException(officeId); }
-
+            this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             String dateFinder = "select MIN(je.entry_date) as entityDate " + "from acc_gl_journal_entry  je "
                     + "where je.is_running_balance_calculated=0  and je.office_id=?";
             try {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
index 205cb1a..207cdc9 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java
@@ -69,9 +69,8 @@ import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidati
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.office.domain.OrganisationCurrencyRepositoryWrapper;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
 import org.apache.fineract.portfolio.client.domain.ClientTransaction;
 import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
 import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
@@ -93,7 +92,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
     private final GLClosureRepository glClosureRepository;
     private final GLAccountRepository glAccountRepository;
     private final JournalEntryRepository glJournalEntryRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final AccountingProcessorForLoanFactory accountingProcessorForLoanFactory;
     private final AccountingProcessorForSavingsFactory accountingProcessorForSavingsFactory;
     private final AccountingProcessorForSharesFactory accountingProcessorForSharesFactory;
@@ -109,7 +108,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
 
     @Autowired
     public JournalEntryWritePlatformServiceJpaRepositoryImpl(final GLClosureRepository glClosureRepository,
-            final JournalEntryRepository glJournalEntryRepository, final OfficeRepository officeRepository,
+            final JournalEntryRepository glJournalEntryRepository, final OfficeRepositoryWrapper officeRepositoryWrapper,
             final GLAccountRepository glAccountRepository, final JournalEntryCommandFromApiJsonDeserializer fromApiJsonDeserializer,
             final AccountingProcessorHelper accountingProcessorHelper, final AccountingRuleRepository accountingRuleRepository,
             final AccountingProcessorForLoanFactory accountingProcessorForLoanFactory,
@@ -121,7 +120,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
             final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepositoryWrapper,
             final CashBasedAccountingProcessorForClientTransactions accountingProcessorForClientTransactions) {
         this.glClosureRepository = glClosureRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.glJournalEntryRepository = glJournalEntryRepository;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.glAccountRepository = glAccountRepository;
@@ -147,9 +146,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
 
             // check office is valid
             final Long officeId = command.longValueOfParameterNamed(JournalEntryJsonInputParams.OFFICE_ID.getValue());
-            final Office office = this.officeRepository.findOne(officeId);
-            if (office == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             final Long accountRuleId = command.longValueOfParameterNamed(JournalEntryJsonInputParams.ACCOUNTING_RULE.getValue());
             final String currencyCode = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.CURRENCY_CODE.getValue());
 
@@ -647,9 +644,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
 
             // check office is valid
             final Long officeId = command.longValueOfParameterNamed(JournalEntryJsonInputParams.OFFICE_ID.getValue());
-            final Office office = this.officeRepository.findOne(officeId);
-            if (office == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             final String currencyCode = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.CURRENCY_CODE.getValue());
 
             validateBusinessRulesForJournalEntries(journalEntryCommand);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java
index 517f20c..3a880ea 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java
@@ -50,7 +50,7 @@ import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
 import org.apache.fineract.organisation.monetary.domain.Money;
 import org.apache.fineract.organisation.monetary.domain.MoneyHelper;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.provisioning.data.ProvisioningCriteriaData;
 import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategory;
 import org.apache.fineract.organisation.provisioning.domain.ProvisioningCategoryRepository;
@@ -72,7 +72,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements
     private final ProvisioningCriteriaReadPlatformService provisioningCriteriaReadPlatformService ;
     private final LoanProductRepository loanProductRepository;
     private final GLAccountRepository glAccountRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final ProvisioningCategoryRepository provisioningCategoryRepository;
     private final PlatformSecurityContext platformSecurityContext;
     private final ProvisioningEntryRepository provisioningEntryRepository;
@@ -85,7 +85,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements
             final ProvisioningEntriesReadPlatformService provisioningEntriesReadPlatformService,
             final ProvisioningCriteriaReadPlatformService provisioningCriteriaReadPlatformService,
             final LoanProductRepository loanProductRepository, final GLAccountRepository glAccountRepository,
-            final OfficeRepository officeRepository, final ProvisioningCategoryRepository provisioningCategoryRepository,
+            final OfficeRepositoryWrapper officeRepositoryWrapper, final ProvisioningCategoryRepository provisioningCategoryRepository,
             final PlatformSecurityContext platformSecurityContext, final ProvisioningEntryRepository provisioningEntryRepository,
             final JournalEntryWritePlatformService journalEntryWritePlatformService,
             final ProvisioningEntriesDefinitionJsonDeserializer fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper) {
@@ -93,7 +93,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements
         this.provisioningCriteriaReadPlatformService = provisioningCriteriaReadPlatformService ;
         this.loanProductRepository = loanProductRepository;
         this.glAccountRepository = glAccountRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.provisioningCategoryRepository = provisioningCategoryRepository;
         this.platformSecurityContext = platformSecurityContext;
         this.provisioningEntryRepository = provisioningEntryRepository;
@@ -221,7 +221,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements
         Map<LoanProductProvisioningEntry, LoanProductProvisioningEntry> provisioningEntries = new HashMap<>();
         for (LoanProductProvisioningEntryData data : entries) {
             LoanProduct loanProduct = this.loanProductRepository.findOne(data.getProductId());
-            Office office = this.officeRepository.findOne(data.getOfficeId());
+            Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(data.getOfficeId());
             ProvisioningCategory provisioningCategory = provisioningCategoryRepository.findOne(data.getCategoryId());
             GLAccount liabilityAccount = glAccountRepository.findOne(data.getLiablityAccount());
             GLAccount expenseAccount = glAccountRepository.findOne(data.getExpenseAccount());

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java
index e81b464..f934541 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java
@@ -47,8 +47,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,17 +63,17 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
     private final AccountingRuleRepositoryWrapper accountingRuleRepositoryWrapper;
     private final AccountingRuleRepository accountingRuleRepository;
     private final GLAccountRepositoryWrapper accountRepositoryWrapper;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final AccountingRuleCommandFromApiJsonDeserializer fromApiJsonDeserializer;
     private final CodeValueRepository codeValueRepository;
 
     @Autowired
     public AccountingRuleWritePlatformServiceJpaRepositoryImpl(final AccountingRuleRepositoryWrapper accountingRuleRepositoryWrapper,
-            final GLAccountRepositoryWrapper accountRepositoryWrapper, final OfficeRepository officeRepository,
+            final GLAccountRepositoryWrapper accountRepositoryWrapper, final OfficeRepositoryWrapper officeRepositoryWrapper,
             final AccountingRuleRepository ruleRepository, final AccountingRuleCommandFromApiJsonDeserializer fromApiJsonDeserializer,
             final CodeValueRepository codeValueRepository) {
         this.accountRepositoryWrapper = accountRepositoryWrapper;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.accountingRuleRepository = ruleRepository;
         this.accountingRuleRepositoryWrapper = accountingRuleRepositoryWrapper;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
@@ -107,8 +106,7 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
             final Long officeId = command.longValueOfParameterNamed(GLClosureJsonInputParams.OFFICE_ID.getValue());
             Office office = null;
             if (officeId != null) {
-                office = this.officeRepository.findOne(officeId);
-                if (office == null) { throw new OfficeNotFoundException(officeId); }
+                office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             }
 
             final AccountingRule accountingRule = assembleAccountingRuleAndTags(office, command);
@@ -268,8 +266,7 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
             }
 
             if (officeId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.OFFICE_ID.getValue())) {
-                final Office userOffice = this.officeRepository.findOne(officeId);
-                if (userOffice == null) { throw new OfficeNotFoundException(officeId); }
+                final Office userOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
                 accountingRule.setOffice(userOffice);
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/processor/TwilioHookProcessor.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/processor/TwilioHookProcessor.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/processor/TwilioHookProcessor.java
index aa87e7c..d3bab53 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/processor/TwilioHookProcessor.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/processor/TwilioHookProcessor.java
@@ -18,44 +18,45 @@
  */
 package org.apache.fineract.infrastructure.hooks.processor;
 
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.apiKeyName;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.fineract.infrastructure.hooks.domain.Hook;
 import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
 import org.apache.fineract.infrastructure.hooks.domain.HookConfigurationRepository;
 import org.apache.fineract.infrastructure.hooks.processor.data.SmsProviderData;
 import org.apache.fineract.portfolio.client.domain.Client;
-import org.apache.fineract.portfolio.client.domain.ClientRepository;
+import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.apache.fineract.template.service.TemplateMergeService;
 import org.apache.fineract.useradministration.domain.AppUser;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import retrofit.Callback;
 
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import retrofit.Callback;
 
-import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.apiKeyName;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 
 @Service
 public class TwilioHookProcessor implements HookProcessor {
 
     private final HookConfigurationRepository hookConfigurationRepository;
     private final TemplateMergeService templateMergeService;
-    private final ClientRepository clientRepository;
+    private final ClientRepositoryWrapper clientRepositoryWrapper;
 
     @Autowired
     public TwilioHookProcessor(
             final HookConfigurationRepository hookConfigurationRepository,
             final TemplateMergeService templateMergeService,
-            final ClientRepository clientRepository) {
+            final ClientRepositoryWrapper clientRepositoryWrapper) {
         this.hookConfigurationRepository = hookConfigurationRepository;
         this.templateMergeService = templateMergeService;
-        this.clientRepository = clientRepository;
+        this.clientRepositoryWrapper = clientRepositoryWrapper;
     }
 
     @Override
@@ -127,7 +128,7 @@ public class TwilioHookProcessor implements HookProcessor {
             if (map.containsKey("clientId")) {
                 final Long clientId = new Long(Integer.toString((int) map
                         .get("clientId")));
-                final Client client = this.clientRepository.findOne(clientId);
+                final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
                 final String mobileNo = client.mobileNo();
                 if (mobileNo != null && !mobileNo.isEmpty()) {
                     this.templateMergeService.setAuthToken(authToken);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java
index d159f3a..04cf4df 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java
@@ -36,8 +36,7 @@ import org.apache.fineract.organisation.holiday.domain.Holiday;
 import org.apache.fineract.organisation.holiday.domain.HolidayRepositoryWrapper;
 import org.apache.fineract.organisation.holiday.exception.HolidayDateException;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.workingdays.domain.WorkingDays;
 import org.apache.fineract.organisation.workingdays.domain.WorkingDaysRepositoryWrapper;
 import org.apache.fineract.organisation.workingdays.service.WorkingDaysUtil;
@@ -61,18 +60,18 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
     private final HolidayRepositoryWrapper holidayRepository;
     private final WorkingDaysRepositoryWrapper daysRepositoryWrapper;
     private final PlatformSecurityContext context;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final FromJsonHelper fromApiJsonHelper;
 
     @Autowired
     public HolidayWritePlatformServiceJpaRepositoryImpl(final HolidayDataValidator fromApiJsonDeserializer,
             final HolidayRepositoryWrapper holidayRepository, final PlatformSecurityContext context,
-            final OfficeRepository officeRepository, final FromJsonHelper fromApiJsonHelper,
+            final OfficeRepositoryWrapper officeRepositoryWrapper, final FromJsonHelper fromApiJsonHelper,
             final WorkingDaysRepositoryWrapper daysRepositoryWrapper) {
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.holidayRepository = holidayRepository;
         this.context = context;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.fromApiJsonHelper = fromApiJsonHelper;
         this.daysRepositoryWrapper = daysRepositoryWrapper;
     }
@@ -162,8 +161,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
             for (int i = 0; i < array.size(); i++) {
                 final JsonObject officeElement = array.get(i).getAsJsonObject();
                 final Long officeId = this.fromApiJsonHelper.extractLongNamed(HolidayApiConstants.officeIdParamName, officeElement);
-                final Office office = this.officeRepository.findOne(officeId);
-                if (office == null) { throw new OfficeNotFoundException(officeId); }
+                final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
                 offices.add(office);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java
index 55a4c65..dadf6d7 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/Office.java
@@ -47,7 +47,7 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
         @UniqueConstraint(columnNames = { "external_id" }, name = "externalid_org") })
 public class Office extends AbstractPersistable<Long> {
 
-    @OneToMany(fetch = FetchType.EAGER)
+    @OneToMany(fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")
     private final List<Office> children = new LinkedList<>();
 
@@ -238,4 +238,8 @@ public class Office extends AbstractPersistable<Long> {
 
         return match;
     }
+    
+    public void loadLazyCollections() {
+        this.children.size() ;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeRepositoryWrapper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeRepositoryWrapper.java
index 36fef09..77dc82c 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeRepositoryWrapper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeRepositoryWrapper.java
@@ -21,6 +21,7 @@ package org.apache.fineract.organisation.office.domain;
 import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -44,12 +45,20 @@ public class OfficeRepositoryWrapper {
         return office;
     }
 
-    public void save(final Office entity) {
-        this.repository.save(entity);
+    @Transactional(readOnly=true)
+    public Office findOfficeHierarchy(final Long id) {
+        final Office office = this.repository.findOne(id);
+        if (office == null) { throw new OfficeNotFoundException(id); }
+        office.loadLazyCollections(); 
+        return office ;
+        
+    }
+    public Office save(final Office entity) {
+        return this.repository.save(entity);
     }
 
-    public void saveAndFlush(final Office entity) {
-        this.repository.saveAndFlush(entity);
+    public Office saveAndFlush(final Office entity) {
+        return this.repository.saveAndFlush(entity);
     }
 
     public void delete(final Office entity) {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java
index 13a8744..1377e47 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java
@@ -31,10 +31,9 @@ import org.apache.fineract.organisation.monetary.domain.ApplicationCurrencyRepos
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
 import org.apache.fineract.organisation.monetary.domain.Money;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.office.domain.OfficeTransaction;
 import org.apache.fineract.organisation.office.domain.OfficeTransactionRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
 import org.apache.fineract.organisation.office.serialization.OfficeCommandFromApiJsonDeserializer;
 import org.apache.fineract.organisation.office.serialization.OfficeTransactionCommandFromApiJsonDeserializer;
 import org.apache.fineract.useradministration.domain.AppUser;
@@ -55,7 +54,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
     private final PlatformSecurityContext context;
     private final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer;
     private final OfficeTransactionCommandFromApiJsonDeserializer moneyTransferCommandFromApiJsonDeserializer;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final OfficeTransactionRepository officeTransactionRepository;
     private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
 
@@ -63,12 +62,12 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
     public OfficeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
             final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer,
             final OfficeTransactionCommandFromApiJsonDeserializer moneyTransferCommandFromApiJsonDeserializer,
-            final OfficeRepository officeRepository, final OfficeTransactionRepository officeMonetaryTransferRepository,
+            final OfficeRepositoryWrapper officeRepositoryWrapper, final OfficeTransactionRepository officeMonetaryTransferRepository,
             final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository) {
         this.context = context;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.moneyTransferCommandFromApiJsonDeserializer = moneyTransferCommandFromApiJsonDeserializer;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.officeTransactionRepository = officeMonetaryTransferRepository;
         this.applicationCurrencyRepository = applicationCurrencyRepository;
     }
@@ -94,11 +93,11 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
             final Office office = Office.fromJson(parent, command);
 
             // pre save to generate id for use in office hierarchy
-            this.officeRepository.save(office);
+            this.officeRepositoryWrapper.save(office);
 
             office.generateHierarchy();
 
-            this.officeRepository.save(office);
+            this.officeRepositoryWrapper.save(office);
 
             return new CommandProcessingResultBuilder() //
                     .withCommandId(command.commandId()) //
@@ -139,7 +138,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
             }
 
             if (!changes.isEmpty()) {
-                this.officeRepository.saveAndFlush(office);
+                this.officeRepositoryWrapper.saveAndFlush(office);
             }
 
             return new CommandProcessingResultBuilder() //
@@ -166,18 +165,16 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
         Office fromOffice = null;
         final Long fromOfficeId = command.longValueOfParameterNamed("fromOfficeId");
         if (fromOfficeId != null) {
-            fromOffice = this.officeRepository.findOne(fromOfficeId);
+            fromOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(fromOfficeId);
             officeId = fromOffice.getId();
         }
         Office toOffice = null;
         final Long toOfficeId = command.longValueOfParameterNamed("toOfficeId");
         if (toOfficeId != null) {
-            toOffice = this.officeRepository.findOne(toOfficeId);
+            toOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(toOfficeId);
             officeId = toOffice.getId();
         }
 
-        if (fromOffice == null && toOffice == null) { throw new OfficeNotFoundException(toOfficeId); }
-
         final String currencyCode = command.stringValueOfParameterNamed("currencyCode");
         final ApplicationCurrency appCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currencyCode);
 
@@ -239,16 +236,13 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
     private Office validateUserPriviledgeOnOfficeAndRetrieve(final AppUser currentUser, final Long officeId) {
 
         final Long userOfficeId = currentUser.getOffice().getId();
-        final Office userOffice = this.officeRepository.findOne(userOfficeId);
-        if (userOffice == null) { throw new OfficeNotFoundException(userOfficeId); }
-
+        final Office userOffice = this.officeRepositoryWrapper.findOfficeHierarchy(userOfficeId);
         if (userOffice.doesNotHaveAnOfficeInHierarchyWithId(officeId)) { throw new NoAuthorizationException(
                 "User does not have sufficient priviledges to act on the provided office."); }
 
         Office officeToReturn = userOffice;
         if (!userOffice.identifiedBy(officeId)) {
-            officeToReturn = this.officeRepository.findOne(officeId);
-            if (officeToReturn == null) { throw new OfficeNotFoundException(officeId); }
+            officeToReturn = this.officeRepositoryWrapper.findOfficeHierarchy(officeId);
         }
 
         return officeToReturn;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java
index a8a6e4f..b10dd12 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java
@@ -26,8 +26,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.organisation.staff.domain.StaffRepository;
 import org.apache.fineract.organisation.staff.exception.StaffNotFoundException;
@@ -46,14 +45,14 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
 
     private final StaffCommandFromApiJsonDeserializer fromApiJsonDeserializer;
     private final StaffRepository staffRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
 
     @Autowired
     public StaffWritePlatformServiceJpaRepositoryImpl(final StaffCommandFromApiJsonDeserializer fromApiJsonDeserializer,
-            final StaffRepository staffRepository, final OfficeRepository officeRepository) {
+            final StaffRepository staffRepository, final OfficeRepositoryWrapper officeRepositoryWrapper) {
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.staffRepository = staffRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
     }
 
     @Transactional
@@ -65,9 +64,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
 
             final Long officeId = command.longValueOfParameterNamed("officeId");
 
-            final Office staffOffice = this.officeRepository.findOne(officeId);
-            if (staffOffice == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office staffOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             final Staff staff = Staff.fromJson(staffOffice, command);
 
             this.staffRepository.save(staff);
@@ -96,9 +93,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
 
             if (changesOnly.containsKey("officeId")) {
                 final Long officeId = (Long) changesOnly.get("officeId");
-                final Office newOffice = this.officeRepository.findOne(officeId);
-                if (newOffice == null) { throw new OfficeNotFoundException(officeId); }
-
+                final Office newOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
                 staffForUpdate.changeOffice(newOffice);
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java
index bff951c..bbaad90 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java
@@ -35,8 +35,7 @@ import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityEx
 import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException;
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.organisation.staff.domain.StaffRepository;
 import org.apache.fineract.organisation.staff.exception.StaffNotFoundException;
@@ -70,7 +69,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
     private final TellerCommandFromApiJsonDeserializer fromApiJsonDeserializer;
     private final TellerRepository tellerRepository;
     private final TellerRepositoryWrapper tellerRepositoryWrapper;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final StaffRepository staffRepository;
     private final CashierRepository cashierRepository;
     private final CashierTransactionRepository cashierTxnRepository;
@@ -80,7 +79,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
     @Autowired
     public TellerWritePlatformServiceJpaImpl(final PlatformSecurityContext context,
             final TellerCommandFromApiJsonDeserializer fromApiJsonDeserializer, final TellerRepository tellerRepository,
-            final TellerRepositoryWrapper tellerRepositoryWrapper, final OfficeRepository officeRepository,
+            final TellerRepositoryWrapper tellerRepositoryWrapper, final OfficeRepositoryWrapper officeRepositoryWrapper,
             final StaffRepository staffRepository, CashierRepository cashierRepository, CashierTransactionRepository cashierTxnRepository,
             JournalEntryRepository glJournalEntryRepository,
             FinancialActivityAccountRepositoryWrapper financialActivityAccountRepositoryWrapper) {
@@ -88,7 +87,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.tellerRepository = tellerRepository;
         this.tellerRepositoryWrapper = tellerRepositoryWrapper;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.staffRepository = staffRepository;
         this.cashierRepository = cashierRepository;
         this.cashierTxnRepository = cashierTxnRepository;
@@ -108,9 +107,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
 
             // final Office parent =
             // validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
-            final Office tellerOffice = this.officeRepository.findOne(officeId);
-            if (tellerOffice == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office tellerOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             final Teller teller = Teller.fromJson(tellerOffice, command);
 
             // pre save to generate id for use in office hierarchy
@@ -133,9 +130,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
         try {
 
             final Long officeId = command.longValueOfParameterNamed("officeId");
-            final Office tellerOffice = this.officeRepository.findOne(officeId);
-            if (tellerOffice == null) { throw new OfficeNotFoundException(officeId); }
-
+            final Office tellerOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
             final AppUser currentUser = this.context.authenticatedUser();
 
             this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json());
@@ -167,9 +162,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
     private Teller validateUserPriviledgeOnTellerAndRetrieve(final AppUser currentUser, final Long tellerId) {
 
         final Long userOfficeId = currentUser.getOffice().getId();
-        final Office userOffice = this.officeRepository.findOne(userOfficeId);
-        if (userOffice == null) { throw new OfficeNotFoundException(userOfficeId); }
-
+        final Office userOffice = this.officeRepositoryWrapper.findOfficeHierarchy(userOfficeId);
         final Teller tellerToReturn = this.tellerRepository.findOne(tellerId);
         if (tellerToReturn != null) {
             final Long tellerOfficeId = tellerToReturn.officeId();

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferDetailAssembler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferDetailAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferDetailAssembler.java
index f9f4f20..4fb18cb 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferDetailAssembler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/domain/AccountTransferDetailAssembler.java
@@ -31,7 +31,7 @@ import java.util.Locale;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.portfolio.client.domain.Client;
 import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
@@ -47,17 +47,17 @@ import com.google.gson.JsonElement;
 public class AccountTransferDetailAssembler {
 
     private final ClientRepositoryWrapper clientRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final SavingsAccountAssembler savingsAccountAssembler;
     private final FromJsonHelper fromApiJsonHelper;
     private final LoanAssembler loanAccountAssembler;
 
     @Autowired
-    public AccountTransferDetailAssembler(final ClientRepositoryWrapper clientRepository, final OfficeRepository officeRepository,
+    public AccountTransferDetailAssembler(final ClientRepositoryWrapper clientRepository, final OfficeRepositoryWrapper officeRepositoryWrapper,
             final SavingsAccountAssembler savingsAccountAssembler, final FromJsonHelper fromApiJsonHelper,
             final LoanAssembler loanAccountAssembler) {
         this.clientRepository = clientRepository;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.savingsAccountAssembler = savingsAccountAssembler;
         this.fromApiJsonHelper = fromApiJsonHelper;
         this.loanAccountAssembler = loanAccountAssembler;
@@ -104,13 +104,13 @@ public class AccountTransferDetailAssembler {
         final JsonElement element = command.parsedJson();
 
         final Long fromOfficeId = this.fromApiJsonHelper.extractLongNamed(fromOfficeIdParamName, element);
-        final Office fromOffice = this.officeRepository.findOne(fromOfficeId);
+        final Office fromOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(fromOfficeId);
 
         final Long fromClientId = this.fromApiJsonHelper.extractLongNamed(fromClientIdParamName, element);
         final Client fromClient = this.clientRepository.findOneWithNotFoundDetection(fromClientId);
 
         final Long toOfficeId = this.fromApiJsonHelper.extractLongNamed(toOfficeIdParamName, element);
-        final Office toOffice = this.officeRepository.findOne(toOfficeId);
+        final Office toOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(toOfficeId);
 
         final Long toClientId = this.fromApiJsonHelper.extractLongNamed(toClientIdParamName, element);
         final Client toClient = this.clientRepository.findOneWithNotFoundDetection(toClientId);
@@ -128,13 +128,13 @@ public class AccountTransferDetailAssembler {
         final JsonElement element = command.parsedJson();
 
         final Long fromOfficeId = this.fromApiJsonHelper.extractLongNamed(fromOfficeIdParamName, element);
-        final Office fromOffice = this.officeRepository.findOne(fromOfficeId);
+        final Office fromOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(fromOfficeId);
 
         final Long fromClientId = this.fromApiJsonHelper.extractLongNamed(fromClientIdParamName, element);
         final Client fromClient = this.clientRepository.findOneWithNotFoundDetection(fromClientId);
 
         final Long toOfficeId = this.fromApiJsonHelper.extractLongNamed(toOfficeIdParamName, element);
-        final Office toOffice = this.officeRepository.findOne(toOfficeId);
+        final Office toOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(toOfficeId);
 
         final Long toClientId = this.fromApiJsonHelper.extractLongNamed(toClientIdParamName, element);
         final Client toClient = this.clientRepository.findOneWithNotFoundDetection(toClientId);
@@ -152,13 +152,13 @@ public class AccountTransferDetailAssembler {
         final JsonElement element = command.parsedJson();
 
         final Long fromOfficeId = this.fromApiJsonHelper.extractLongNamed(fromOfficeIdParamName, element);
-        final Office fromOffice = this.officeRepository.findOne(fromOfficeId);
+        final Office fromOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(fromOfficeId);
 
         final Long fromClientId = this.fromApiJsonHelper.extractLongNamed(fromClientIdParamName, element);
         final Client fromClient = this.clientRepository.findOneWithNotFoundDetection(fromClientId);
 
         final Long toOfficeId = this.fromApiJsonHelper.extractLongNamed(toOfficeIdParamName, element);
-        final Office toOffice = this.officeRepository.findOne(toOfficeId);
+        final Office toOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(toOfficeId);
 
         final Long toClientId = this.fromApiJsonHelper.extractLongNamed(toClientIdParamName, element);
         final Client toClient = this.clientRepository.findOneWithNotFoundDetection(toClientId);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
index 847b20d..c15b950 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
@@ -33,7 +33,7 @@ import org.apache.fineract.portfolio.client.domain.Client;
 import org.apache.fineract.portfolio.client.domain.ClientAddress;
 import org.apache.fineract.portfolio.client.domain.ClientAddressRepository;
 import org.apache.fineract.portfolio.client.domain.ClientAddressRepositoryWrapper;
-import org.apache.fineract.portfolio.client.domain.ClientRepository;
+import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -45,7 +45,7 @@ public class AddressWritePlatformServiceImpl implements AddressWritePlatformServ
 	private final PlatformSecurityContext context;
 	private final CodeValueRepository codeValueRepository;
 	private final ClientAddressRepository clientAddressRepository;
-	private final ClientRepository clientRepository;
+	private final ClientRepositoryWrapper clientRepositoryWrapper;
 	private final AddressRepository addressRepository;
 	private final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper;
 	private final AddressCommandFromApiJsonDeserializer fromApiJsonDeserializer;
@@ -53,13 +53,13 @@ public class AddressWritePlatformServiceImpl implements AddressWritePlatformServ
 	@Autowired
 	public AddressWritePlatformServiceImpl(final PlatformSecurityContext context,
 			final CodeValueRepository codeValueRepository, final ClientAddressRepository clientAddressRepository,
-			final ClientRepository clientRepository, final AddressRepository addressRepository,
+			final ClientRepositoryWrapper clientRepositoryWrapper, final AddressRepository addressRepository,
 			final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper,
 			final AddressCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
 		this.context = context;
 		this.codeValueRepository = codeValueRepository;
 		this.clientAddressRepository = clientAddressRepository;
-		this.clientRepository = clientRepository;
+		this.clientRepositoryWrapper = clientRepositoryWrapper;
 		this.addressRepository = addressRepository;
 		this.clientAddressRepositoryWrapper = clientAddressRepositoryWrapper;
 		this.fromApiJsonDeserializer = fromApiJsonDeserializer;
@@ -96,7 +96,7 @@ public class AddressWritePlatformServiceImpl implements AddressWritePlatformServ
 		final Long addressid = add.getId();
 		final Address addobj = this.addressRepository.getOne(addressid);
 
-		final Client client = this.clientRepository.getOne(clientId);
+		final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
 		final boolean isActive = command.booleanPrimitiveValueOfParameterNamed("isActive");
 
 		final ClientAddress clientAddressobj = ClientAddress.fromJson(isActive, client, addobj, addressTypeIdObj);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java
index be01e2b..1851483 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java
@@ -49,7 +49,7 @@ import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.apache.fineract.portfolio.group.domain.Group;
 import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
-import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
 import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
 import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
 import org.joda.time.LocalDate;
@@ -69,7 +69,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
     private final LoanWritePlatformService loanWritePlatformService;
     private final ConfigurationDomainService configurationDomainService;
     private final GroupRepositoryWrapper groupRepository;
-    private final LoanRepository loanRepository;
+    private final LoanRepositoryWrapper loanRepositoryWrapper;
     private final ClientRepositoryWrapper clientRepository;
 
     @Autowired
@@ -78,7 +78,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
             final CalendarCommandFromApiJsonDeserializer fromApiJsonDeserializer,
             final CalendarInstanceRepository calendarInstanceRepository, final LoanWritePlatformService loanWritePlatformService,
             final ConfigurationDomainService configurationDomainService, final GroupRepositoryWrapper groupRepository,
-            final LoanRepository loanRepository, final ClientRepositoryWrapper clientRepository) {
+            final LoanRepositoryWrapper loanRepositoryWrapper, final ClientRepositoryWrapper clientRepository) {
         this.calendarRepository = calendarRepository;
         this.calendarHistoryRepository = calendarHistoryRepository;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
@@ -86,7 +86,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
         this.loanWritePlatformService = loanWritePlatformService;
         this.configurationDomainService = configurationDomainService;
         this.groupRepository = groupRepository;
-        this.loanRepository = loanRepository;
+        this.loanRepositoryWrapper = loanRepositoryWrapper;
         this.clientRepository = clientRepository;
     }
 
@@ -104,7 +104,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
             entityType = centerOrGroup.isCenter() ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS;
             entityId = command.getGroupId();
         } else if (command.getLoanId() != null) {
-            final Loan loan = this.loanRepository.findOne(command.getLoanId());
+            final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(command.getLoanId(), true);
             entityActivationDate = (loan.getApprovedOnDate() == null) ? loan.getSubmittedOnDate() : loan.getApprovedOnDate();
             entityType = CalendarEntityType.LOANS;
             entityId = command.getLoanId();

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
index 82b994b..a857b4b 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
@@ -54,8 +54,6 @@ import org.apache.fineract.organisation.office.domain.Office;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.portfolio.client.api.ClientApiConstants;
 import org.apache.fineract.portfolio.group.domain.Group;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
-import org.apache.fineract.portfolio.savings.domain.SavingsProduct;
 import org.apache.fineract.useradministration.domain.AppUser;
 import org.joda.time.LocalDate;
 import org.joda.time.format.DateTimeFormatter;
@@ -132,7 +130,7 @@ public final class Client extends AbstractPersistable<Long> {
     @JoinColumn(name = "staff_id")
     private Staff staff;
 
-    @ManyToMany(fetch=FetchType.EAGER)
+    @ManyToMany(fetch=FetchType.LAZY)
     @JoinTable(name = "m_group_client", joinColumns = @JoinColumn(name = "client_id"), inverseJoinColumns = @JoinColumn(name = "group_id"))
     private Set<Group> groups;
 
@@ -203,13 +201,11 @@ public final class Client extends AbstractPersistable<Long> {
     @JoinColumn(name = "activatedon_userid", nullable = true)
     private AppUser activatedBy;
 
-    @ManyToOne
-    @JoinColumn(name = "default_savings_product", nullable = true)
-    private SavingsProduct savingsProduct;
-
-    @ManyToOne
-    @JoinColumn(name = "default_savings_account", nullable = true)
-    private SavingsAccount savingsAccount;
+    @Column(name = "default_savings_product", nullable = true)
+    private Long savingsProductId;
+    
+    @Column(name = "default_savings_account", nullable = true)
+    private Long savingsAccountId;
 
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "client_type_cv_id", nullable = true)
@@ -222,16 +218,16 @@ public final class Client extends AbstractPersistable<Long> {
     @Column(name = "legal_form_enum", nullable = true)
     private Integer legalForm;
 
-	@Column(name = "reopened_on_date", nullable = true)
-	@Temporal(TemporalType.DATE)
-	private Date reopenedDate;
+    @Column(name = "reopened_on_date", nullable = true)
+    @Temporal(TemporalType.DATE)
+    private Date reopenedDate;
 
-	@ManyToOne(optional = true, fetch=FetchType.LAZY)
-	@JoinColumn(name = "reopened_by_userid", nullable = true)
-	private AppUser reopenedBy;
+    @ManyToOne(optional = true, fetch = FetchType.LAZY)
+    @JoinColumn(name = "reopened_by_userid", nullable = true)
+    private AppUser reopenedBy;
 
     public static Client createNew(final AppUser currentUser, final Office clientOffice, final Group clientParentGroup, final Staff staff,
-            final SavingsProduct savingsProduct, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification,
+            final Long savingsProductId, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification,
             final Integer legalForm, final JsonCommand command) {
 
         final String accountNo = command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName);
@@ -266,9 +262,9 @@ public final class Client extends AbstractPersistable<Long> {
         if (command.hasParameter(ClientApiConstants.submittedOnDateParamName)) {
             submittedOnDate = command.localDateValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName);
         }
-        final SavingsAccount account = null;
+        final Long savingsAccountId = null;
         return new Client(currentUser, status, clientOffice, clientParentGroup, accountNo, firstname, middlename, lastname, fullname,
-                activationDate, officeJoiningDate, externalId, mobileNo, staff, submittedOnDate, savingsProduct, account, dataOfBirth,
+                activationDate, officeJoiningDate, externalId, mobileNo, staff, submittedOnDate, savingsProductId, savingsAccountId, dataOfBirth,
                 gender, clientType, clientClassification, legalForm);
     }
 
@@ -279,7 +275,7 @@ public final class Client extends AbstractPersistable<Long> {
     private Client(final AppUser currentUser, final ClientStatus status, final Office office, final Group clientParentGroup,
             final String accountNo, final String firstname, final String middlename, final String lastname, final String fullname,
             final LocalDate activationDate, final LocalDate officeJoiningDate, final String externalId, final String mobileNo,
-            final Staff staff, final LocalDate submittedOnDate, final SavingsProduct savingsProduct, final SavingsAccount savingsAccount,
+            final Staff staff, final LocalDate submittedOnDate, final Long savingsProductId, final Long savingsAccountId,
             final LocalDate dateOfBirth, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification, final Integer legalForm) {
 
         if (StringUtils.isBlank(accountNo)) {
@@ -343,8 +339,8 @@ public final class Client extends AbstractPersistable<Long> {
         }
 
         this.staff = staff;
-        this.savingsProduct = savingsProduct;
-        this.savingsAccount = savingsAccount;
+        this.savingsProductId = savingsProductId;
+        this.savingsAccountId = savingsAccountId;
 
         if (gender != null) {
             this.gender = gender;
@@ -863,32 +859,24 @@ public final class Client extends AbstractPersistable<Long> {
         return false;
     }
 
-    private Long savingsProductId() {
-        Long savingsProductId = null;
-        if (this.savingsProduct != null) {
-            savingsProductId = this.savingsProduct.getId();
-        }
-        return savingsProductId;
-    }
-
-    public SavingsProduct SavingsProduct() {
-        return this.savingsProduct;
+    public Long savingsProductId() {
+        return this.savingsProductId;
     }
 
-    public void updateSavingsProduct(SavingsProduct savingsProduct) {
-        this.savingsProduct = savingsProduct;
+    public void updateSavingsProduct(final Long savingsProductId) {
+        this.savingsProductId = savingsProductId;
     }
 
     public AppUser activatedBy() {
         return this.activatedBy;
     }
 
-    public SavingsAccount savingsAccount() {
-        return this.savingsAccount;
+    public Long savingsAccountId() {
+        return this.savingsAccountId;
     }
 
-    public void updateSavingsAccount(SavingsAccount savingsAccount) {
-        this.savingsAccount = savingsAccount;
+    public void updateSavingsAccount(Long savingsAccountId) {
+        this.savingsAccountId = savingsAccountId;
     }
 
     public Long genderId() {
@@ -996,20 +984,24 @@ public final class Client extends AbstractPersistable<Long> {
 
     }
     
-	public void reOpened(AppUser currentUser, Date reopenedDate) {
-		this.reopenedDate = reopenedDate;
-		this.reopenedBy = currentUser;
-		this.updatedBy = currentUser;
-		this.updatedOnDate = reopenedDate;
-		this.status = ClientStatus.PENDING.getValue();
+    public void reOpened(AppUser currentUser, Date reopenedDate) {
+        this.reopenedDate = reopenedDate;
+        this.reopenedBy = currentUser;
+        this.updatedBy = currentUser;
+        this.updatedOnDate = reopenedDate;
+        this.status = ClientStatus.PENDING.getValue();
 
-	}
+    }
 
-	public Integer getLegalForm() {
-		return legalForm;
-	}
+    public Integer getLegalForm() {
+        return legalForm;
+    }
 
-	public void setLegalForm(Integer legalForm) {
-		this.legalForm = legalForm;
-	}
+    public void setLegalForm(Integer legalForm) {
+        this.legalForm = legalForm;
+    }
+    
+    public void loadLazyCollections() {
+        this.groups.size() ;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
index 1dbe0b9..a9624b5 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
@@ -25,7 +25,6 @@ import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
-import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.portfolio.address.domain.Address;
 import org.springframework.data.jpa.domain.AbstractPersistable;
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepository.java
index c1f9c27..e718265 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepository.java
@@ -21,6 +21,6 @@ package org.apache.fineract.portfolio.client.domain;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 
-public interface ClientRepository extends JpaRepository<Client, Long>, JpaSpecificationExecutor<Client> {
+abstract interface ClientRepository extends JpaRepository<Client, Long>, JpaSpecificationExecutor<Client> {
     // no added behaviour
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepositoryWrapper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepositoryWrapper.java
index 27840ee..bdfccb9 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepositoryWrapper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientRepositoryWrapper.java
@@ -18,11 +18,15 @@
  */
 package org.apache.fineract.portfolio.client.domain;
 
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.portfolio.client.exception.ClientNotActiveException;
 import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -43,11 +47,22 @@ public class ClientRepositoryWrapper {
     }
 
     public Client findOneWithNotFoundDetection(final Long id) {
-        final Client client = this.repository.findOne(id);
-        if (client == null) { throw new ClientNotFoundException(id); }
-        return client;
+       return this.findOneWithNotFoundDetection(id, false) ;
     }
 
+    @Transactional(readOnly=true)
+    public Client findOneWithNotFoundDetection(final Long clientId, final boolean loadLazyCollections) {
+        final Client client = this.repository.findOne(clientId);
+        if (client == null) { throw new ClientNotFoundException(clientId); }
+        if(loadLazyCollections) {
+            client.loadLazyCollections();
+        }
+        return client;
+    }
+    
+    public List<Client> findAll(final Collection<Long> clientIds) {
+        return this.repository.findAll(clientIds) ;   
+    }
     public void save(final Client client) {
         this.repository.save(client);
     }