Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hibernate-orm property: quarkus.hibernate-orm.validation.enabled #30617

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .../src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public class HibernateOrmConfigPersistenceUnit {
@ConfigItem(defaultValue = "true")
public boolean secondLevelCachingEnabled;

/**
* Bean Validation configuration.
*/
@ConfigItem
public HibernateOrmConfigPersistenceValidation 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
Expand Down Expand Up @@ -496,4 +502,15 @@ public enum IdentifierQuotingStrategy {
ALL_EXCEPT_COLUMN_DEFINITIONS,
ONLY_KEYWORDS
}

@ConfigGroup
public static class HibernateOrmConfigPersistenceValidation {

/**
* Enables the Bean Validation integration.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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"));

@Test
@Transactional
public void testValidEntity() {
String entityName = "Post method should not persist an entity having a Size constraint of 50 on the name column if validation was enabled.";
RestAssured.given().body(entityName).when().post("/validation").then()
.body(is("OK"));
}

}
Original file line number Diff line number Diff line change
@@ -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