From e8b55e8f2e6b84a344bbbe55e01951f91d36d849 Mon Sep 17 00:00:00 2001
From: Tudor Malene <tudor.malene@r3.com>
Date: Fri, 21 Jun 2019 09:33:37 +0100
Subject: [PATCH] CORDA-2934 - disable hibernate validator integration with
 hibernate (#5130) (#5144)

(cherry picked from commit 688c74270618b0b4fceed32748b5265de1441a51)
---
 docs/source/changelog.rst                                   | 6 ++++++
 .../nodeapi/internal/persistence/HibernateConfiguration.kt  | 1 +
 2 files changed, 7 insertions(+)

diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst
index 34506e237f..5806b1669c 100644
--- a/docs/source/changelog.rst
+++ b/docs/source/changelog.rst
@@ -9,6 +9,12 @@ Unreleased
 
 * Fix a bug in Corda 4.0 that combined commands in ``TransactionBuilder`` if they only differed by the signers list.  The behaviour is now consistent with prior Corda releases.
 
+* Disabled the default loading of ``hibernate-validator`` as a plugin by hibernate when a CorDapp depends on it. This change will in turn fix the
+  (https://github.com/corda/corda/issues/4444) issue, because nodes will no longer need to add ``hibernate-validator`` to the ``\libs`` folder.
+  For nodes that already did that, it can be safely removed when the latest Corda is installed.
+  One thing to keep in mind is that if any CorDapp relied on hibernate-validator to validate Querayable JPA Entities via annotations, that will no longer happen.
+  That was a bad practice anyway, because the ``ContractState`` should be validated in the Contract verify method.
+
 .. _changelog_v4.0:
 
 Version 4.0
diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt
index 637848d155..fa5cfcbb24 100644
--- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt
+++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt
@@ -89,6 +89,7 @@ class HibernateConfiguration(
         val config = Configuration(metadataSources).setProperty("hibernate.connection.provider_class", NodeDatabaseConnectionProvider::class.java.name)
                 .setProperty("hibernate.format_sql", "true")
                 .setProperty("hibernate.hbm2ddl.auto", hbm2dll)
+                .setProperty("javax.persistence.validation.mode", "none")
                 .setProperty("hibernate.connection.isolation", databaseConfig.transactionIsolationLevel.jdbcValue.toString())
 
         schemas.forEach { schema ->