fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [6/7] incubator-fineract git commit: OpenJPA Integration Changes
Date Mon, 17 Oct 2016 08:19:26 GMT
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
index 4707af1..42ccf4e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableCustom.java
@@ -22,16 +22,17 @@ import java.io.Serializable;
 import java.util.Date;
 
 import javax.persistence.Column;
+import javax.persistence.FetchType;
 import javax.persistence.JoinColumn;
 import javax.persistence.MappedSuperclass;
 import javax.persistence.OneToOne;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
+import org.apache.fineract.useradministration.domain.AppUser;
 import org.joda.time.DateTime;
 import org.springframework.data.domain.Auditable;
 import org.springframework.data.jpa.domain.AbstractAuditable;
-import org.springframework.data.jpa.domain.AbstractPersistable;
 
 /**
  * A custom copy of {@link AbstractAuditable} to override the column names used
@@ -46,21 +47,21 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
  *            the type of the auditing type's identifier
  */
 @MappedSuperclass
-public abstract class AbstractAuditableCustom<U, PK extends Serializable> extends AbstractPersistable<PK> implements Auditable<U, PK> {
+public abstract class AbstractAuditableCustom<U, PK extends Serializable> extends AbstractPersistableCustom<PK> implements Auditable<AppUser, Long> {
 
     private static final long serialVersionUID = 141481953116476081L;
 
-    @OneToOne
+    @OneToOne(fetch=FetchType.LAZY)
     @JoinColumn(name = "createdby_id")
-    private U createdBy;
+    private AppUser createdBy;
 
     @Column(name = "created_date")
     @Temporal(TemporalType.TIMESTAMP)
     private Date createdDate;
 
-    @OneToOne
+    @OneToOne(fetch=FetchType.LAZY)
     @JoinColumn(name = "lastmodifiedby_id")
-    private U lastModifiedBy;
+    private AppUser lastModifiedBy;
 
     @Column(name = "lastmodified_date")
     @Temporal(TemporalType.TIMESTAMP)
@@ -72,7 +73,7 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
      * @see org.springframework.data.domain.Auditable#getCreatedBy()
      */
     @Override
-    public U getCreatedBy() {
+    public AppUser getCreatedBy() {
 
         return this.createdBy;
     }
@@ -84,7 +85,7 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
      * org.springframework.data.domain.Auditable#setCreatedBy(java.lang.Object)
      */
     @Override
-    public void setCreatedBy(final U createdBy) {
+    public void setCreatedBy(final AppUser createdBy) {
 
         this.createdBy = createdBy;
     }
@@ -119,7 +120,7 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
      * @see org.springframework.data.domain.Auditable#getLastModifiedBy()
      */
     @Override
-    public U getLastModifiedBy() {
+    public AppUser getLastModifiedBy() {
 
         return this.lastModifiedBy;
     }
@@ -132,7 +133,7 @@ public abstract class AbstractAuditableCustom<U, PK extends Serializable> extend
      * .Object)
      */
     @Override
-    public void setLastModifiedBy(final U lastModifiedBy) {
+    public void setLastModifiedBy(final AppUser lastModifiedBy) {
 
         this.lastModifiedBy = lastModifiedBy;
     }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
new file mode 100644
index 0000000..a1ca55a
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractPersistableCustom.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.core.domain;
+
+import java.io.Serializable;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+import org.springframework.data.domain.Persistable;
+
+
+@MappedSuperclass
+public abstract class AbstractPersistableCustom<PK extends Serializable> implements Persistable<Long> {
+
+        @Id
+        @GeneratedValue(strategy = GenerationType.IDENTITY)
+        private Long id;
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see org.springframework.data.domain.Persistable#getId()
+         */
+        @Override
+        public Long getId() {
+                return id;
+        }
+
+        /**
+         * Sets the id of the entity.
+         * 
+         * @param id the id to set
+         */
+        protected void setId(final Long id) {
+
+                this.id = id;
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see org.springframework.data.domain.Persistable#isNew()
+         */
+        @Override
+        public boolean isNew() {
+
+                return null == this.id;
+        }
+
+        //We have removed toString(), hashCode() and equals() methods. By adding them end up issues with OpenJPA
+}

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java
new file mode 100644
index 0000000..24dc0ad
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.core.domain;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.openjpa.jdbc.sql.BooleanRepresentationFactory;
+import org.apache.openjpa.jdbc.sql.MySQLDictionary;
+
+public class MySQLDictionaryCustom extends MySQLDictionary {
+
+        public MySQLDictionaryCustom(){
+                super();
+            this.supportsSubselect = true;
+            this.booleanRepresentation = BooleanRepresentationFactory.BOOLEAN;
+            this.supportsGetGeneratedKeys = false ;
+            this.allowsAliasInBulkClause = true ;
+            this.useWildCardForCount = true ;
+        }
+        
+        @Override
+        public void connectedConfiguration(Connection conn) throws SQLException {
+                super.connectedConfiguration(conn);
+                this.supportsSubselect = true;
+                this.supportsGetGeneratedKeys = false ;
+                this.allowsAliasInBulkClause = true ;
+                this.useWildCardForCount = true ;
+        }
+}

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
index 34782a4..7f9be71 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
@@ -106,7 +106,8 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
         poolConfiguration.setRemoveAbandonedTimeout(tenantConnectionObj.getRemoveAbandonedTimeout());
         poolConfiguration.setLogAbandoned(tenantConnectionObj.isLogAbandoned());
         poolConfiguration.setAbandonWhenPercentageFull(tenantConnectionObj.getAbandonWhenPercentageFull());
-
+        poolConfiguration.setDefaultAutoCommit(true);
+        
         /**
          * Vishwas- Do we need to enable the below properties and add
          * ResetAbandonedTimer for long running batch Jobs?

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/Report.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/Report.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/Report.java
index 4d8fe02..e39a591 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/Report.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/Report.java
@@ -40,13 +40,13 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
 import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
 import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 import com.google.gson.JsonArray;
 
 @Entity
 @Table(name = "stretchy_report", uniqueConstraints = { @UniqueConstraint(columnNames = { "report_name" }, name = "unq_report_name") })
-public final class Report extends AbstractPersistable<Long> {
+public final class Report extends AbstractPersistableCustom<Long> {
 
     @Column(name = "report_name", nullable = false, unique = true)
     private String reportName;
@@ -74,7 +74,7 @@ public final class Report extends AbstractPersistable<Long> {
     private String reportSql;
 
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "report", orphanRemoval = true, fetch=FetchType.EAGER)
-    private final Set<ReportParameterUsage> reportParameterUsages = new HashSet<>();
+    private Set<ReportParameterUsage> reportParameterUsages = new HashSet<>();
 
     public static Report fromJson(final JsonCommand command, final Collection<String> reportTypes) {
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameter.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameter.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameter.java
index 6d5ba22..298e740 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameter.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameter.java
@@ -21,11 +21,11 @@ package org.apache.fineract.infrastructure.dataqueries.domain;
 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 = "stretchy_parameter")
-public class ReportParameter extends AbstractPersistable<Long> {
+public class ReportParameter extends AbstractPersistableCustom<Long> {
 
     protected ReportParameter() {
         //

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameterUsage.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameterUsage.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameterUsage.java
index 43f6744..4d10fef 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameterUsage.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportParameterUsage.java
@@ -24,13 +24,11 @@ import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "stretchy_report_parameter")
-public final class ReportParameterUsage extends AbstractPersistable<Long> {
+public final class ReportParameterUsage extends AbstractPersistableCustom<Long> {
 
     @ManyToOne(optional = false)
     @JoinColumn(name = "report_id", nullable = false)
@@ -53,7 +51,7 @@ public final class ReportParameterUsage extends AbstractPersistable<Long> {
         this.reportParameterName = reportParameterName;
     }
 
-    @Override
+    /*@Override
     public boolean equals(final Object obj) {
         if (obj == null) { return false; }
         if (obj == this) { return true; }
@@ -75,7 +73,7 @@ public final class ReportParameterUsage extends AbstractPersistable<Long> {
                 .append(this.parameter.getId()) //
                 .append(this.reportParameterName) //
                 .toHashCode();
-    }
+    }*/
 
     public boolean hasIdOf(final Long id) {
         return getId().equals(id);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
index a9b79a5..c40b949 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
@@ -28,10 +28,12 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
+import javax.persistence.PersistenceException;
 import javax.sql.DataSource;
 
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.codes.service.CodeReadPlatformService;
 import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -65,6 +67,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataAccessException;
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
@@ -264,7 +267,18 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             // show duplicate datatable error msg
             if (realCause.getMessage()
                     .contains("Duplicate entry") || cause.getMessage()
-                    .contains("Duplicate entry")) { throw new PlatformDataIntegrityException("error.msg.datatable.registered",
+                    .contains("Duplicate entry")) { 
+            	throw new PlatformDataIntegrityException("error.msg.datatable.registered",
+                            "Datatable `" + dataTableName + "` is already registered against an application table.", "dataTableName",
+                            dataTableName); }
+            logAsErrorUnexpectedDataIntegrityException(dve);
+            throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
+                    "Unknown data integrity issue with resource.");
+        }catch (final PersistenceException dve) {
+        	final Throwable cause = dve.getCause() ;
+        	if (cause.getMessage()
+                    .contains("Duplicate entry")) { 
+        		throw new PlatformDataIntegrityException("error.msg.datatable.registered",
                             "Datatable `" + dataTableName + "` is already registered against an application table.", "dataTableName",
                             dataTableName); }
             logAsErrorUnexpectedDataIntegrityException(dve);
@@ -374,6 +388,19 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             logAsErrorUnexpectedDataIntegrityException(dve);
             throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
                     "Unknown data integrity issue with resource.");
+        }catch(final PersistenceException e) {
+        	final Throwable cause = e.getCause() ;
+            if (cause.getMessage()
+                    .contains("Duplicate entry")) { 
+            	throw new PlatformDataIntegrityException(
+                            "error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
+                                    + "` and application table with identifier `" + appTableId + "`.",
+                            "dataTableName", dataTableName, appTableId); }
+
+            logAsErrorUnexpectedDataIntegrityException(e);
+            throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
+                    "Unknown data integrity issue with resource.");
+        	
         }
     }
 
@@ -408,6 +435,17 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             logAsErrorUnexpectedDataIntegrityException(dve);
             throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
                     "Unknown data integrity issue with resource.");
+        }catch (final PersistenceException dve) {
+            final Throwable cause = dve.getCause() ;
+            if (cause.getMessage()
+                    .contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
+                            "error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
+                                    + "` and application table with identifier `" + appTableId + "`.",
+                            "dataTableName", dataTableName, appTableId); }
+
+            logAsErrorUnexpectedDataIntegrityException(dve);
+            throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
+                    "Unknown data integrity issue with resource.");
         }
     }
 
@@ -574,6 +612,21 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             }
 
             throwExceptionIfValidationWarningsExist(dataValidationErrors);
+        }catch (final PersistenceException | BadSqlGrammarException ee) {
+        	Throwable realCause = ExceptionUtils.getRootCause(ee.getCause()) ;
+        	 final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+             final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable");
+             if (realCause.getMessage().toLowerCase().contains("duplicate column name")) {
+                 baseDataValidator.reset().parameter("name").failWithCode("duplicate.column.name");
+             } else if (realCause.getMessage().contains("Table") && realCause.getMessage().contains("already exists")) {
+                 baseDataValidator.reset().parameter("datatableName").value(datatableName).failWithCode("datatable.already.exists");
+             } else if (realCause.getMessage().contains("Column") && realCause.getMessage().contains("big")) {
+                 baseDataValidator.reset().parameter("column").failWithCode("length.too.big");
+             } else if (realCause.getMessage().contains("Row") && realCause.getMessage().contains("large")) {
+                 baseDataValidator.reset().parameter("row").failWithCode("size.too.large");
+             }
+
+             throwExceptionIfValidationWarningsExist(dataValidationErrors);
         }
 
         return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
@@ -942,7 +995,22 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             }
 
             throwExceptionIfValidationWarningsExist(dataValidationErrors);
-        }
+        }catch (final PersistenceException ee) {
+        	Throwable realCause = ExceptionUtils.getRootCause(ee.getCause()) ;
+       	 	final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+            final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable");
+            if (realCause.getMessage().toLowerCase().contains("duplicate column name")) {
+                baseDataValidator.reset().parameter("name").failWithCode("duplicate.column.name");
+            } else if (realCause.getMessage().contains("Table") && realCause.getMessage().contains("already exists")) {
+                baseDataValidator.reset().parameter("datatableName").value(datatableName).failWithCode("datatable.already.exists");
+            } else if (realCause.getMessage().contains("Column") && realCause.getMessage().contains("big")) {
+                baseDataValidator.reset().parameter("column").failWithCode("length.too.big");
+            } else if (realCause.getMessage().contains("Row") && realCause.getMessage().contains("large")) {
+                baseDataValidator.reset().parameter("row").failWithCode("size.too.large");
+            }
+
+            throwExceptionIfValidationWarningsExist(dataValidationErrors);
+       }
     }
 
     @Transactional

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java
index eb54824..25d3d18 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java
@@ -22,7 +22,10 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import javax.persistence.PersistenceException;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
@@ -100,8 +103,12 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic
                     .withEntityId(report.getId()) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleReportDataIntegrityIssues(command, dve);
+            handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleReportDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -137,8 +144,12 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic
                     .with(changes) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleReportDataIntegrityIssues(command, dve);
+            handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleReportDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -169,10 +180,9 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic
      * Guaranteed to throw an exception no matter what the data integrity issue
      * is.
      */
-    private void handleReportDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
+    private void handleReportDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
 
-        final Throwable realCause = dve.getMostSpecificCause();
-        if (realCause.getMessage().contains("unq_report_name")) {
+        if (realCause.getMessage().contains("unq_report_name") || realCause.getMessage().contains("report_name_UNIQUE")) {
             final String name = command.stringValueOfParameterNamed("reportName");
             throw new PlatformDataIntegrityException("error.msg.report.duplicate.name", "A report with name '" + name + "' already exists",
                     "name", name);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Document.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Document.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Document.java
index eb311b6..5272252 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Document.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Document.java
@@ -24,11 +24,11 @@ import javax.persistence.Table;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommand;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_document")
-public class Document extends AbstractPersistable<Long> {
+public class Document extends AbstractPersistableCustom<Long> {
 
     @Column(name = "parent_entity_type", length = 50)
     private String parentEntityType;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Image.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Image.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Image.java
index c27a182..f355142 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Image.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/domain/Image.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 = "m_image")
-public final class Image extends AbstractPersistable<Long> {
+public final class Image extends AbstractPersistableCustom<Long> {
 
     @Column(name = "location", length = 500)
     private String location;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityAccess.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityAccess.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityAccess.java
index 75c852a..93e87d9 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityAccess.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityAccess.java
@@ -30,11 +30,11 @@ import javax.persistence.Table;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.entityaccess.FineractEntityAccessConstants;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_entity_to_entity_access")
-public class FineractEntityAccess extends AbstractPersistable<Long> {
+public class FineractEntityAccess extends AbstractPersistableCustom<Long> {
 	
 	@Column(name = "entity_type", length = 50)
     private String entityType;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelation.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelation.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelation.java
index b3d46c0..0ca00ff 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelation.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelation.java
@@ -27,11 +27,11 @@ import javax.persistence.Entity;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_entity_relation")
-public class FineractEntityRelation extends AbstractPersistable<Long> {
+public class FineractEntityRelation extends AbstractPersistableCustom<Long> {
 
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "relationId", orphanRemoval = true)
     private Set<FineractEntityToEntityMapping> fineractEntityToEntityMapping = new HashSet<>();

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelationRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelationRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelationRepository.java
index 81e9da6..ed409b1 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelationRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityRelationRepository.java
@@ -24,6 +24,6 @@ import org.springframework.data.repository.query.Param;
 
 public interface FineractEntityRelationRepository extends JpaRepository<FineractEntityRelation, Long>{
 
-	@Query("from FineractEntityRelation fea where fea.codeName= :codeName")
+	@Query("select fea from FineractEntityRelation fea where fea.codeName= :codeName")
 	FineractEntityRelation findOneByCodeName(@Param("codeName") String codeName);
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMapping.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMapping.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMapping.java
index 2ae9ef8..86f8e99 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMapping.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMapping.java
@@ -34,11 +34,11 @@ import javax.persistence.UniqueConstraint;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.entityaccess.api.FineractEntityApiResourceConstants;
 import org.apache.fineract.infrastructure.entityaccess.exception.FineractEntityToEntityMappingDateException;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_entity_to_entity_mapping", uniqueConstraints = { @UniqueConstraint(columnNames = { "rel_id", "from_id", "to_id" }) })
-public class FineractEntityToEntityMapping extends AbstractPersistable<Long> {
+public class FineractEntityToEntityMapping extends AbstractPersistableCustom<Long> {
 
     @ManyToOne
     @JoinColumn(name = "rel_id")
@@ -50,11 +50,11 @@ public class FineractEntityToEntityMapping extends AbstractPersistable<Long> {
     @Column(name = "to_id")
     private Long toId;
 
-    @Column(name = "start_date", nullable = false)
+    @Column(name = "start_date", nullable = true)
     @Temporal(TemporalType.DATE)
     private Date startDate;
 
-    @Column(name = "end_date", nullable = false)
+    @Column(name = "end_date", nullable = true)
     @Temporal(TemporalType.DATE)
     private Date endDate;
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMappingRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMappingRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMappingRepository.java
index 5ec3293..b67f6e1 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMappingRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/domain/FineractEntityToEntityMappingRepository.java
@@ -27,6 +27,6 @@ public interface FineractEntityToEntityMappingRepository extends JpaRepository<F
     
    
 
-	@Query("from FineractEntityToEntityMapping feem where feem.fromId= :fromId and feem.toId= :toId and feem.relationId= :relId")
+	@Query("select feem from FineractEntityToEntityMapping feem where feem.fromId= :fromId and feem.toId= :toId and feem.relationId= :relId")
 	FineractEntityToEntityMapping findListByProductId(@Param("relId")FineractEntityRelation relId, @Param("toId")Long toId, @Param("fromId")Long fromId );
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java
index 914a238..eb86eaf 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java
@@ -21,6 +21,9 @@ package org.apache.fineract.infrastructure.entityaccess.service;
 import java.util.Date;
 import java.util.Map;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
@@ -107,8 +110,12 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
 
             return new CommandProcessingResultBuilder().withEntityId(newMap.getId()).withCommandId(command.commandId()).build();
         } catch (final DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -136,8 +143,12 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
             return new CommandProcessingResultBuilder(). //
                     withEntityId(mapForUpdate.getId()).withCommandId(command.commandId()).build();
         } catch (DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -154,9 +165,8 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
 
     }
 
-    private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
+    private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) {
 
-        final Throwable realCause = dve.getMostSpecificCause();
         realCause.printStackTrace();
         if (realCause.getMessage().contains("rel_id_from_id_to_id")) {
             final String fromId = command.stringValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType);
@@ -169,7 +179,7 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces
         throw new PlatformDataIntegrityException("error.msg.entity.mapping", "Unknown data integrity issue with resource.");
     }
 
-    private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) {
+    private void logAsErrorUnexpectedDataIntegrityException(final Exception dve) {
         logger.error(dve.getMessage(), dve);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookConfiguration.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookConfiguration.java
index 5ed0e66..410fa55 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookConfiguration.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookConfiguration.java
@@ -24,11 +24,11 @@ import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_hook_configuration")
-public class HookConfiguration extends AbstractPersistable<Long> {
+public class HookConfiguration extends AbstractPersistableCustom<Long> {
 
 	@ManyToOne(optional = false)
 	@JoinColumn(name = "hook_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/infrastructure/hooks/domain/HookRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookRepository.java
index 9501142..123b194 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookRepository.java
@@ -28,12 +28,12 @@ import org.springframework.data.repository.query.Param;
 public interface HookRepository extends JpaRepository<Hook, Long>,
 		JpaSpecificationExecutor<Hook> {
 
-	@Query("select hook from Hook hook inner join hook.events event where event.entityName = :entityName and event.actionName = :actionName and hook.isActive = 1")
+	@Query("select hook from Hook hook inner join hook.events event where event.entityName = :entityName and event.actionName = :actionName and hook.isActive = true")
 	List<Hook> findAllHooksListeningToEvent(
 			@Param("entityName") String entityName,
 			@Param("actionName") String actionName);
 
-	@Query("from Hook hook where hook.template.id = :templateId ")
+	@Query("select hook from Hook hook where hook.template.id = :templateId ")
 	Hook findOneByTemplateId(@Param("templateId") Long templateId);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookResource.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookResource.java
index 9b6b2f6..161dbe6 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookResource.java
@@ -24,11 +24,11 @@ import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_hook_registered_events")
-public class HookResource extends AbstractPersistable<Long> {
+public class HookResource extends AbstractPersistableCustom<Long> {
 
 	@ManyToOne(optional = false)
 	@JoinColumn(name = "hook_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/infrastructure/hooks/domain/HookTemplate.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplate.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplate.java
index 904db7a..9294ad2 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplate.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplate.java
@@ -32,17 +32,17 @@ import javax.persistence.Table;
 
 import org.apache.commons.lang.StringUtils;
 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_hook_templates")
-public class HookTemplate extends AbstractPersistable<Long> {
+public class HookTemplate extends AbstractPersistableCustom<Long> {
 
 	@Column(name = "name", nullable = false, length = 100)
 	private String name;
 
 	@OneToMany(cascade = CascadeType.ALL, mappedBy = "template", orphanRemoval = true, fetch=FetchType.EAGER)
-	private final Set<Schema> fields = new HashSet<>();
+	private Set<Schema> fields = new HashSet<>();
 
 	private HookTemplate(final String name) {
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplateRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplateRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplateRepository.java
index 2902b40..c0e53a7 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplateRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/HookTemplateRepository.java
@@ -27,6 +27,6 @@ public interface HookTemplateRepository extends
 		JpaRepository<HookTemplate, Long>,
 		JpaSpecificationExecutor<HookTemplate> {
 
-	@Query("from HookTemplate template where template.name = :name")
+	@Query("select template from HookTemplate template where template.name = :name")
 	HookTemplate findOne(@Param("name") String name);
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/Schema.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/Schema.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/Schema.java
index 728e292..223abe5 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/Schema.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/domain/Schema.java
@@ -24,11 +24,11 @@ import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_hook_schema")
-public class Schema extends AbstractPersistable<Long> {
+public class Schema extends AbstractPersistableCustom<Long> {
 
 	@ManyToOne(optional = false)
 	@JoinColumn(name = "hook_template_id", referencedColumnName = "id", nullable = false)
@@ -44,7 +44,7 @@ public class Schema extends AbstractPersistable<Long> {
 	private String placeholder;
 
 	@Column(name = "optional", nullable = false)
-	private final boolean optional = false;
+	private boolean optional = false;
 
 	public Schema() {
 		//

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java
index 1696512..d7e682e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java
@@ -18,9 +18,26 @@
  */
 package org.apache.fineract.infrastructure.hooks.service;
 
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.actionNameParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.configParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.contentTypeName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.entityNameParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.eventsParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.nameParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.payloadURLName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.templateIdParamName;
+import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.webTemplateName;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.ApiParameterError;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
@@ -29,7 +46,13 @@ import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
 import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
 import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
 import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
-import org.apache.fineract.infrastructure.hooks.domain.*;
+import org.apache.fineract.infrastructure.hooks.domain.Hook;
+import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
+import org.apache.fineract.infrastructure.hooks.domain.HookRepository;
+import org.apache.fineract.infrastructure.hooks.domain.HookResource;
+import org.apache.fineract.infrastructure.hooks.domain.HookTemplate;
+import org.apache.fineract.infrastructure.hooks.domain.HookTemplateRepository;
+import org.apache.fineract.infrastructure.hooks.domain.Schema;
 import org.apache.fineract.infrastructure.hooks.exception.HookNotFoundException;
 import org.apache.fineract.infrastructure.hooks.exception.HookTemplateNotFoundException;
 import org.apache.fineract.infrastructure.hooks.processor.ProcessorHelper;
@@ -44,12 +67,11 @@ import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import retrofit.RetrofitError;
 
-import java.util.*;
-import java.util.Map.Entry;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
 
-import static org.apache.fineract.infrastructure.hooks.api.HookApiConstants.*;
+import retrofit.RetrofitError;
 
 @Service
 public class HookWritePlatformServiceJpaRepositoryImpl
@@ -117,8 +139,12 @@ public class HookWritePlatformServiceJpaRepositoryImpl
                     .withCommandId(command.commandId())
                     .withEntityId(hook.getId()).build();
         } catch (final DataIntegrityViolationException dve) {
-            handleHookDataIntegrityIssues(command, dve);
+            handleHookDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleHookDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -181,8 +207,12 @@ public class HookWritePlatformServiceJpaRepositoryImpl
                     .with(changes) //
                     .build();
         } catch (final DataIntegrityViolationException dve) {
-            handleHookDataIntegrityIssues(command, dve);
-            return null;
+            handleHookDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
+            return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleHookDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -192,12 +222,9 @@ public class HookWritePlatformServiceJpaRepositoryImpl
     public CommandProcessingResult deleteHook(final Long hookId) {
 
         this.context.authenticatedUser();
-
         final Hook hook = retrieveHookBy(hookId);
-
         try {
             this.hookRepository.delete(hook);
-            this.hookRepository.flush();
         } catch (final DataIntegrityViolationException e) {
             throw new PlatformDataIntegrityException(
                     "error.msg.unknown.data.integrity.issue",
@@ -348,9 +375,8 @@ public class HookWritePlatformServiceJpaRepositoryImpl
         }
     }
 
-    private void handleHookDataIntegrityIssues(final JsonCommand command,
-            final DataIntegrityViolationException dve) {
-        final Throwable realCause = dve.getMostSpecificCause();
+    private void handleHookDataIntegrityIssues(final JsonCommand command, final Throwable realCause,
+            final Exception dve) {
         if (realCause.getMessage().contains("hook_name")) {
             final String name = command.stringValueOfParameterNamed("name");
             throw new PlatformDataIntegrityException(

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetail.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetail.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetail.java
index 659c3db..752f3d0 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetail.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetail.java
@@ -31,11 +31,11 @@ import javax.persistence.TemporalType;
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.jobs.api.SchedulerJobApiConstants;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "job")
-public class ScheduledJobDetail extends AbstractPersistable<Long> {
+public class ScheduledJobDetail extends AbstractPersistableCustom<Long> {
 
     @Column(name = "name")
     private String jobName;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetailRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetailRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetailRepository.java
index 86140a2..d786748 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetailRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobDetailRepository.java
@@ -28,14 +28,14 @@ import org.springframework.data.repository.query.Param;
 
 public interface ScheduledJobDetailRepository extends JpaRepository<ScheduledJobDetail, Long>, JpaSpecificationExecutor<ScheduledJobDetail> {
 
-    @Query("from ScheduledJobDetail jobDetail where jobDetail.jobKey = :jobKey")
+    @Query("select jobDetail from ScheduledJobDetail jobDetail where jobDetail.jobKey = :jobKey")
     ScheduledJobDetail findByJobKey(@Param("jobKey") String jobKey);
 
-    @Query("from ScheduledJobDetail jobDetail where jobDetail.id=:jobId")
+    @Query("select jobDetail from ScheduledJobDetail jobDetail where jobDetail.id=:jobId")
     ScheduledJobDetail findByJobId(@Param("jobId") Long jobId);
 
     @Lock(value = LockModeType.PESSIMISTIC_WRITE)
-    @Query("from ScheduledJobDetail jobDetail where jobDetail.jobKey = :jobKey")
+    @Query("select jobDetail from ScheduledJobDetail jobDetail where jobDetail.jobKey = :jobKey")
     ScheduledJobDetail findByJobKeyWithLock(@Param("jobKey") String jobKey);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobRunHistory.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobRunHistory.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobRunHistory.java
index 8c66002..c60fe48 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobRunHistory.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/ScheduledJobRunHistory.java
@@ -28,11 +28,11 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "job_run_history")
-public class ScheduledJobRunHistory extends AbstractPersistable<Long> {
+public class ScheduledJobRunHistory extends AbstractPersistableCustom<Long> {
 
     @ManyToOne
     @JoinColumn(name = "job_id")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/SchedulerDetail.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/SchedulerDetail.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/SchedulerDetail.java
index 0afb31b..675e8f9 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/SchedulerDetail.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/domain/SchedulerDetail.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 = "scheduler_detail")
-public class SchedulerDetail extends AbstractPersistable<Long> {
+public class SchedulerDetail extends AbstractPersistableCustom<Long> {
 
     @Column(name = "execute_misfired_jobs")
     private boolean executeInstructionForMisfiredJobs;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfiguration.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfiguration.java
index 17eb7b6..b14c833 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfiguration.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfiguration.java
@@ -23,11 +23,11 @@ import javax.persistence.Entity;
 import javax.persistence.Table;
 import javax.persistence.UniqueConstraint;
 
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_report_mailing_job_configuration", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "unique_name") })
-public class ReportMailingJobConfiguration extends AbstractPersistable<Integer> {
+public class ReportMailingJobConfiguration extends AbstractPersistableCustom<Integer> {
     private static final long serialVersionUID = 3099279770861263184L;
 
     @Column(name = "name", nullable = false)

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java
index 4839ed6..99d1ef9 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRunHistory.java
@@ -28,12 +28,12 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.joda.time.DateTime;
-import org.springframework.data.jpa.domain.AbstractPersistable;
 
 @Entity
 @Table(name = "m_report_mailing_job_run_history")
-public class ReportMailingJobRunHistory extends AbstractPersistable<Long> {
+public class ReportMailingJobRunHistory extends AbstractPersistableCustom<Long> {
     private static final long serialVersionUID = -3757370929988421076L;
 
     @ManyToOne

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java
index 003f086..377834a 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/domain/SmsMessage.java
@@ -33,11 +33,11 @@ import org.apache.fineract.infrastructure.sms.SmsApiConstants;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.portfolio.client.domain.Client;
 import org.apache.fineract.portfolio.group.domain.Group;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "sms_messages_outbound")
-public class SmsMessage extends AbstractPersistable<Long> {
+public class SmsMessage extends AbstractPersistableCustom<Long> {
 
     @ManyToOne
     @JoinColumn(name = "group_id", nullable = true)

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/Likelihood.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/Likelihood.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/Likelihood.java
index 60f2481..914451d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/Likelihood.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/Likelihood.java
@@ -28,11 +28,11 @@ import javax.persistence.Table;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.survey.api.LikelihoodApiConstants;
 import org.apache.fineract.infrastructure.survey.data.LikelihoodStatus;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "ppi_likelihoods_ppi")
-public final class Likelihood extends AbstractPersistable<Long> {
+public final class Likelihood extends AbstractPersistableCustom<Long> {
 
     @Column(name = "ppi_name", nullable = false)
     private String ppiName;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/LikelihoodRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/LikelihoodRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/LikelihoodRepository.java
index dc49753..681c3eb 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/LikelihoodRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/domain/LikelihoodRepository.java
@@ -29,7 +29,7 @@ import java.util.List;
 
 public interface LikelihoodRepository extends JpaRepository<Likelihood, Long>, JpaSpecificationExecutor<Likelihood> {
 
-   @Query("FROM Likelihood WHERE ppi_name =:ppiName AND id !=:id")
+   @Query("select liklihood FROM Likelihood liklihood WHERE ppi_name =:ppiName AND id <>:id")
    List<Likelihood> findByPpiNameAndLikeliHoodId(@Param("ppiName") String ppiName,@Param("id") Long likeliHoodId);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/mix/domain/MixTaxonomyMapping.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/mix/domain/MixTaxonomyMapping.java b/fineract-provider/src/main/java/org/apache/fineract/mix/domain/MixTaxonomyMapping.java
index 6573f93..3215bcc 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/mix/domain/MixTaxonomyMapping.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/mix/domain/MixTaxonomyMapping.java
@@ -24,11 +24,11 @@ import javax.persistence.Table;
 
 import org.apache.commons.lang.StringUtils;
 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 = "mix_taxonomy_mapping")
-public class MixTaxonomyMapping extends AbstractPersistable<Long> {
+public class MixTaxonomyMapping extends AbstractPersistableCustom<Long> {
 
     @Column(name = "identifier")
     private String identifier;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/Holiday.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/Holiday.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/Holiday.java
index e506a58..be79b25 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/Holiday.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/Holiday.java
@@ -54,13 +54,13 @@ import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidati
 import org.apache.fineract.organisation.holiday.api.HolidayApiConstants;
 import org.apache.fineract.organisation.office.domain.Office;
 import org.joda.time.LocalDate;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 import com.google.gson.JsonArray;
 
 @Entity
 @Table(name = "m_holiday", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "holiday_name") })
-public class Holiday extends AbstractPersistable<Long> {
+public class Holiday extends AbstractPersistableCustom<Long> {
 
     @Column(name = "name", unique = true, nullable = false, length = 100)
     private String name;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/HolidayRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/HolidayRepository.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/HolidayRepository.java
index 9be986e..f7e4e19 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/HolidayRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/domain/HolidayRepository.java
@@ -32,6 +32,6 @@ public interface HolidayRepository extends JpaRepository<Holiday, Long>, JpaSpec
     List<Holiday> findByOfficeIdAndGreaterThanDate(@Param("officeId") Long officeId, @Param("date") Date date,
             @Param("status") Integer status);
 
-    @Query("from Holiday holiday where holiday.processed = false and holiday.status = :status")
+    @Query("select holiday from Holiday holiday where holiday.processed = false and holiday.status = :status")
     List<Holiday> findUnprocessed(@Param("status") Integer status);
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/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 04cf4df..6bce676 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
@@ -24,6 +24,9 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import javax.persistence.PersistenceException;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
@@ -94,8 +97,12 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
 
             return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()).build();
         } catch (final DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -124,8 +131,12 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
 
             return new CommandProcessingResultBuilder().withEntityId(holiday.getId()).with(changes).build();
         } catch (final DataIntegrityViolationException dve) {
-            handleDataIntegrityIssues(command, dve);
+            handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
             return CommandProcessingResult.empty();
+        }catch (final PersistenceException dve) {
+        	Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()) ;
+        	handleDataIntegrityIssues(command, throwable, dve);
+        	return CommandProcessingResult.empty();
         }
     }
 
@@ -168,8 +179,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
         return offices;
     }
 
-    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("holiday_name")) {
             final String name = command.stringValueOfParameterNamed("name");
             throw new PlatformDataIntegrityException("error.msg.holiday.duplicate.name", "Holiday 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/organisation/monetary/domain/ApplicationCurrency.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/ApplicationCurrency.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/ApplicationCurrency.java
index 911a4f9..352c85a 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/ApplicationCurrency.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/ApplicationCurrency.java
@@ -24,29 +24,29 @@ import javax.persistence.Table;
 
 import org.apache.fineract.organisation.monetary.data.CurrencyData;
 import org.apache.fineract.organisation.office.domain.OrganisationCurrency;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_currency")
-public class ApplicationCurrency extends AbstractPersistable<Long> {
+public class ApplicationCurrency extends AbstractPersistableCustom<Long> {
 
     @Column(name = "code", nullable = false, length = 3)
-    private final String code;
+    private String code;
 
     @Column(name = "decimal_places", nullable = false)
-    private final Integer decimalPlaces;
+    private Integer decimalPlaces;
 
     @Column(name = "currency_multiplesof")
-    private final Integer inMultiplesOf;
+    private Integer inMultiplesOf;
 
     @Column(name = "name", nullable = false, length = 50)
-    private final String name;
+    private String name;
 
     @Column(name = "internationalized_name_code", nullable = false, length = 50)
-    private final String nameCode;
+    private String nameCode;
 
     @Column(name = "display_symbol", nullable = true, length = 10)
-    private final String displaySymbol;
+    private String displaySymbol;
 
     protected ApplicationCurrency() {
         this.code = null;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MonetaryCurrency.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MonetaryCurrency.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MonetaryCurrency.java
index 641567b..d91ebc4 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MonetaryCurrency.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MonetaryCurrency.java
@@ -25,13 +25,13 @@ import javax.persistence.Embeddable;
 public class MonetaryCurrency {
 
     @Column(name = "currency_code", length = 3, nullable = false)
-    private final String code;
+    private String code;
 
     @Column(name = "currency_digits", nullable = false)
-    private final int digitsAfterDecimal;
+    private int digitsAfterDecimal;
 
     @Column(name = "currency_multiplesof")
-    private final Integer inMultiplesOf;
+    private Integer inMultiplesOf;
 
     protected MonetaryCurrency() {
         this.code = null;

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java
index d8960f4..8ffdb18 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java
@@ -29,16 +29,16 @@ import javax.persistence.Embeddable;
 public class Money implements Comparable<Money> {
 
     @Column(name = "currency_code", length = 3)
-    private final String currencyCode;
+    private String currencyCode;
 
     @Column(name = "currency_digits")
-    private final int currencyDigitsAfterDecimal;
+    private int currencyDigitsAfterDecimal;
 
     @Column(name = "currency_multiplesof")
-    private final Integer inMultiplesOf;
+    private Integer inMultiplesOf;
 
     @Column(name = "amount", scale = 6, precision = 19)
-    private final BigDecimal amount;
+    private BigDecimal amount;
 
     public static Money total(final Money... monies) {
         if (monies.length == 0) { throw new IllegalArgumentException("Money array must not be empty"); }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/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 dadf6d7..c64e856 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
@@ -37,19 +37,19 @@ import javax.persistence.UniqueConstraint;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.apache.fineract.organisation.office.exception.CannotUpdateOfficeWithParentOfficeSameAsSelf;
 import org.apache.fineract.organisation.office.exception.RootOfficeParentCannotBeUpdated;
 import org.joda.time.LocalDate;
-import org.springframework.data.jpa.domain.AbstractPersistable;
 
 @Entity
 @Table(name = "m_office", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_org"),
         @UniqueConstraint(columnNames = { "external_id" }, name = "externalid_org") })
-public class Office extends AbstractPersistable<Long> {
+public class Office extends AbstractPersistableCustom<Long> {
 
     @OneToMany(fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")
-    private final List<Office> children = new LinkedList<>();
+    private List<Office> children = new LinkedList<>();
 
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java
index d08ba1f..986c364 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OfficeTransaction.java
@@ -35,11 +35,11 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
 import org.apache.fineract.organisation.monetary.domain.Money;
 import org.joda.time.LocalDate;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 @Entity
 @Table(name = "m_office_transaction")
-public class OfficeTransaction extends AbstractPersistable<Long> {
+public class OfficeTransaction extends AbstractPersistableCustom<Long> {
 
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "from_office_id")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/9d7f1c21/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OrganisationCurrency.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OrganisationCurrency.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OrganisationCurrency.java
index 894628a..43263ef 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OrganisationCurrency.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/domain/OrganisationCurrency.java
@@ -23,32 +23,32 @@ import javax.persistence.Entity;
 import javax.persistence.Table;
 
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
-import org.springframework.data.jpa.domain.AbstractPersistable;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 
 /**
  * Represents currencies allowed for this MFI/organisation.
  */
 @Entity
 @Table(name = "m_organisation_currency")
-public class OrganisationCurrency extends AbstractPersistable<Long> {
+public class OrganisationCurrency extends AbstractPersistableCustom<Long> {
 
     @Column(name = "code", nullable = false, length = 3)
-    private final String code;
+    private String code;
 
     @Column(name = "decimal_places", nullable = false)
-    private final Integer decimalPlaces;
+    private Integer decimalPlaces;
 
     @Column(name = "currency_multiplesof")
-    private final Integer inMultiplesOf;
+    private Integer inMultiplesOf;
 
     @Column(name = "name", nullable = false, length = 50)
-    private final String name;
+    private String name;
 
     @Column(name = "internationalized_name_code", nullable = false, length = 50)
-    private final String nameCode;
+    private String nameCode;
 
     @Column(name = "display_symbol", nullable = true, length = 10)
-    private final String displaySymbol;
+    private String displaySymbol;
 
     protected OrganisationCurrency() {
         this.code = null;


Mime
View raw message