Revert ValidationMode.CALLBACK on JPA bootstrap
In gh-30549 we applied changes to the `DefaultPersistenceUnitManager` to use the `ValidationMode.CALLBACK` to better detect invalid validation setup and enforce bootstrap failures in those cases. Unfortunately, doing so disables the detection of validation annotation on entities during the schema creation phase. This is a known Hibernate issue. This commit reverts this change until HHH-12287 is fixed. Fixes gh-31726
This commit is contained in:
parent
7a221eb581
commit
61dd9fce73
|
|
@ -10,7 +10,6 @@ dependencies {
|
|||
optional(project(":spring-context"))
|
||||
optional(project(":spring-web"))
|
||||
optional("jakarta.servlet:jakarta.servlet-api")
|
||||
optional("jakarta.validation:jakarta.validation-api")
|
||||
optional("org.eclipse.persistence:org.eclipse.persistence.jpa")
|
||||
optional("org.hibernate:hibernate-core-jakarta")
|
||||
testImplementation(project(":spring-core-test"))
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ import jakarta.persistence.PersistenceException;
|
|||
import jakarta.persistence.SharedCacheMode;
|
||||
import jakarta.persistence.ValidationMode;
|
||||
import jakarta.persistence.spi.PersistenceUnitInfo;
|
||||
import jakarta.validation.NoProviderFoundException;
|
||||
import jakarta.validation.Validation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
|
@ -50,7 +48,6 @@ import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
|
|||
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
|
||||
import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
|
|
@ -103,9 +100,6 @@ public class DefaultPersistenceUnitManager
|
|||
public static final String ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME = "default";
|
||||
|
||||
|
||||
private static final boolean beanValidationPresent = ClassUtils.isPresent(
|
||||
"jakarta.validation.Validation", DefaultPersistenceUnitManager.class.getClassLoader());
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private String[] persistenceXmlLocations = new String[] {DEFAULT_PERSISTENCE_XML_LOCATION};
|
||||
|
|
@ -465,16 +459,11 @@ public class DefaultPersistenceUnitManager
|
|||
if (this.sharedCacheMode != null) {
|
||||
pui.setSharedCacheMode(this.sharedCacheMode);
|
||||
}
|
||||
|
||||
// Override validation mode or pre-resolve provider detection
|
||||
// Setting validationMode != ValidationMode.AUTO will ignore bean validation
|
||||
// during schema generation, see https://hibernate.atlassian.net/browse/HHH-12287
|
||||
if (this.validationMode != null) {
|
||||
pui.setValidationMode(this.validationMode);
|
||||
}
|
||||
else if (pui.getValidationMode() == ValidationMode.AUTO) {
|
||||
pui.setValidationMode(
|
||||
beanValidationPresent && BeanValidationDelegate.isValidationProviderPresent() ?
|
||||
ValidationMode.CALLBACK : ValidationMode.NONE);
|
||||
}
|
||||
|
||||
// Initialize persistence unit ClassLoader
|
||||
if (this.loadTimeWeaver != null) {
|
||||
|
|
@ -710,21 +699,4 @@ public class DefaultPersistenceUnitManager
|
|||
return pui;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on the Bean Validation API at runtime.
|
||||
*/
|
||||
private static class BeanValidationDelegate {
|
||||
|
||||
static boolean isValidationProviderPresent() {
|
||||
try {
|
||||
Validation.byDefaultProvider().configure();
|
||||
return true;
|
||||
}
|
||||
catch (NoProviderFoundException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue