diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java old mode 100644 new mode 100755 index 8b451d302230a0..960cf2a231ee1a --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java @@ -219,6 +219,13 @@ public class HibernateOrmConfigPersistenceUnit { @ConfigItem(defaultValue = "true") public boolean secondLevelCachingEnabled; + /** + * This flag controls hibernate validation of entities + */ + + @ConfigItem + public HibernateOrmConfigPersistenceValidator validation; + /** * Defines the method for multi-tenancy (DATABASE, NONE, SCHEMA). The complete list of allowed values is available in the * https://javadoc.io/doc/org.hibernate/hibernate-core/5.6.10.Final/org/hibernate/MultiTenancyStrategy.html[Hibernate ORM @@ -496,4 +503,17 @@ public enum IdentifierQuotingStrategy { ALL_EXCEPT_COLUMN_DEFINITIONS, ONLY_KEYWORDS } + + @ConfigGroup + public static class HibernateOrmConfigPersistenceValidator { + + /** + * Enables the Bean Validation integration + */ + + @ConfigItem(defaultValue = "true") + public boolean enabled; + + } + } diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java old mode 100644 new mode 100755 index cbcf48eefe3714..cd98bf5ae3d65a --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -1183,7 +1183,11 @@ private static void producePersistenceUnitDescriptorFromConfig( // Hibernate Validator integration: we force the callback mode to have bootstrap errors reported rather than validation ignored // if there is any issue when bootstrapping Hibernate Validator. if (capabilities.isPresent(Capability.HIBERNATE_VALIDATOR)) { - descriptor.getProperties().setProperty(AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name()); + if (persistenceUnitConfig.validation.enabled) { + descriptor.getProperties().setProperty(AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name()); + } else { + descriptor.getProperties().setProperty(AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.NONE.name()); + } } // Collect the storage engines if MySQL or MariaDB diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/validation/JPAValidationDisabledTestCase.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/validation/JPAValidationDisabledTestCase.java new file mode 100755 index 00000000000000..1b42aa88d13cb2 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/validation/JPAValidationDisabledTestCase.java @@ -0,0 +1,32 @@ +package io.quarkus.hibernate.orm.validation; + +import static org.hamcrest.Matchers.is; + +import javax.transaction.Transactional; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.MyEntity; +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class JPAValidationDisabledTestCase { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(MyEntity.class, JPATestValidationResource.class) + .addAsResource("application-validation-disabled.properties", "application.properties")); + + //define an empty import.sql file + + @Test + @Transactional + public void testValidEntity() { + String entityName = MyEntity.ENTITY_NAME_TOO_LONG; + RestAssured.given().body(entityName).when().post("/validation").then() + .body(is("OK")); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/test/resources/application-validation-disabled.properties b/extensions/hibernate-orm/deployment/src/test/resources/application-validation-disabled.properties new file mode 100755 index 00000000000000..bf76287adc5daf --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/resources/application-validation-disabled.properties @@ -0,0 +1,6 @@ +quarkus.datasource.db-kind=h2 +quarkus.datasource.jdbc.url=jdbc:h2:mem:test + +#quarkus.hibernate-orm.log.sql=true +quarkus.hibernate-orm.validation.enabled=false +quarkus.hibernate-orm.database.generation=drop-and-create