Skip to content

Commit 773205b

Browse files
committed
HHH-19210 Take into account NoProviderFoundException when ValidationMode.AUTO is requested
1 parent a262777 commit 773205b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Set;
1717
import java.util.StringTokenizer;
1818

19+
import jakarta.validation.NoProviderFoundException;
1920
import jakarta.validation.constraints.Digits;
2021
import jakarta.validation.constraints.Max;
2122
import jakarta.validation.constraints.Min;
@@ -97,14 +98,24 @@ public static void activate(ActivationContext context) {
9798
catch (IntegrationException e) {
9899
final Set<ValidationMode> validationModes = context.getValidationModes();
99100
if ( validationModes.contains( ValidationMode.CALLBACK ) ) {
100-
throw new IntegrationException( "Bean Validation provider was not available, but 'callback' validation was requested", e );
101+
throw new IntegrationException( "Jakarta Validation provider was not available, but 'callback' validation mode was requested", e );
101102
}
102103
else if ( validationModes.contains( ValidationMode.DDL ) ) {
103-
throw new IntegrationException( "Bean Validation provider was not available, but 'ddl' validation was requested", e );
104+
throw new IntegrationException( "Jakarta Validation provider was not available, but 'ddl' validation mode was requested", e );
104105
}
105106
else {
106-
LOG.debug( "Unable to acquire Bean Validation ValidatorFactory, skipping activation" );
107-
return;
107+
if ( e.getCause() != null && e.getCause() instanceof NoProviderFoundException ) {
108+
// all good, we are looking at the ValidationMode.AUTO, and there are no providers available.
109+
// Hence, we just don't enable the Jakarta Validation integration:
110+
LOG.debug( "Unable to acquire Jakarta Validation ValidatorFactory, skipping activation" );
111+
return;
112+
}
113+
else {
114+
// There is a Jakarta Validation provider, but it failed to bootstrap the factory for some reason,
115+
// we should fail and let the user deal with it:
116+
throw e;
117+
118+
}
108119
}
109120
}
110121

0 commit comments

Comments
 (0)