Top Description Methods
org.hibernate.validator

public Interface HibernateValidatorContext

extends ValidatorContext
Known Direct Implementers
org.hibernate.validator.internal.engine.PredefinedScopeValidatorContextImpl, org.hibernate.validator.internal.engine.ValidatorContextImpl
Imports
java.time.Duration, jakarta.validation.ClockProvider, .ConstraintValidatorFactory, .MessageInterpolator, .ParameterNameProvider, .TraversableResolver, .ValidatorContext, jakarta.validation.valueextraction.ValueExtractor

Represents a Hibernate Validator specific context that is used to create jakarta.validation.Validator instances. Adds additional configuration options to those provided by ValidatorContext.
Authors
Emmanuel Bernard, Kevin Pollet <[email protected]> (C) 2011 SERLI, Gunnar Morling, Chris Beckey <[email protected]>

Method Summary

Modifier and TypeMethod and Description
public HibernateValidatorContext
addValueExtractor(ValueExtractor<?>
value extractor implementation
extractor
)

Redeclares jakarta.validation.ValidatorContext.addValueExtractor.

Adds a value extractor to be used by the Validator.
public HibernateValidatorContext

Returns:

this following the chaining method pattern
allowMultipleCascadedValidationOnReturnValues
(boolean
flag determining whether validation will allow multiple cascaded validation on return values.
allow
)

Define whether more than one constraint on a return value may be marked for cascading validation are allowed.

public HibernateValidatorContext

Returns:

this following the chaining method pattern
allowOverridingMethodAlterParameterConstraint
(boolean
flag determining whether validation will allow overriding to alter parameter constraints.
allow
)

Define whether overriding methods that override constraints should throw a ConstraintDefinitionException.

public HibernateValidatorContext

Returns:

this following the chaining method pattern
allowParallelMethodsDefineParameterConstraints
(boolean
flag determining whether validation will allow parameter constraints in parallel hierarchies
allow
)

Define whether parallel methods that define constraints should throw a ConstraintDefinitionException.

public HibernateValidatorContext
clockProvider(ClockProvider
ClockProvider implementation
clockProvider
)

Redeclares jakarta.validation.ValidatorContext.clockProvider.

Defines the ClockProvider implementation used by the Validator.
public HibernateValidatorContext
constraintValidatorFactory(ConstraintValidatorFactory
the ConstraintValidatorFactory used by the Validator
factory
)

Redeclares jakarta.validation.ValidatorContext.constraintValidatorFactory.

Defines the constraint validator factory implementation used by the Validator.
public HibernateValidatorContext

Returns:

this following the chaining method pattern
constraintValidatorPayload
(Object
the payload passed to constraint validators
constraintValidatorPayload
)

Define a payload passed to the constraint validators.

public HibernateValidatorContext

Returns:

this following the chaining method pattern
enableTraversableResolverResultCache
(boolean
flag determining whether per validation call caching is enabled for TraversableResolver results.
enabled
)

Define whether the per validation call caching of TraversableResolver results is enabled.

public HibernateValidatorContext

Returns:

this following the chaining method pattern
failFast
(boolean
true to enable fail fast, false otherwise.
failFast
)

En- or disables the fail fast mode.

public HibernateValidatorContext
messageInterpolator(MessageInterpolator
the MessageInterpolator used by the Validator
messageInterpolator
)

Redeclares jakarta.validation.ValidatorContext.messageInterpolator.

Defines the message interpolator implementation used by the Validator.
public HibernateValidatorContext
parameterNameProvider(ParameterNameProvider
parameter name provider implementation.
parameterNameProvider
)

Redeclares jakarta.validation.ValidatorContext.parameterNameProvider.

Defines the parameter name provider implementation used by the Validator.
public HibernateValidatorContext

Returns:

this following the chaining method pattern
showValidatedValuesInTraceLogs
(boolean
true to show the values at trace level, false otherwise.
enabled
)

Define whether values that are currently being validated should be part of the logging at trace level, or not.

public HibernateValidatorContext

Returns:

this following the chaining method pattern
temporalValidationTolerance
(Duration
the tolerance
temporalValidationTolerance
)

Define the temporal validation tolerance i.e. the acceptable margin of error when comparing date/time in temporal constraints.

public HibernateValidatorContext
traversableResolver(TraversableResolver
the TraversableResolver used by the Validator
traversableResolver
)

Redeclares jakarta.validation.ValidatorContext.traversableResolver.

Defines the traversable resolver implementation used by the Validator.
Inherited from jakarta.validation.ValidatorContext:
getValidator

Method Detail

addValueExtractorback to summary
public HibernateValidatorContext addValueExtractor(ValueExtractor<?> extractor)

Redeclares jakarta.validation.ValidatorContext.addValueExtractor.

Doc from jakarta.validation.ValidatorContext.addValueExtractor.

Adds a value extractor to be used by the Validator. Has priority over any extractor for the same type and type parameter detected through the service loader, given in the XML configuration or configured for the validator factory.

Parameters
extractor:ValueExtractor<?>

value extractor implementation

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override
Since
6.0
allowMultipleCascadedValidationOnReturnValuesback to summary
public HibernateValidatorContext allowMultipleCascadedValidationOnReturnValues(boolean allow)

Define whether more than one constraint on a return value may be marked for cascading validation are allowed. The default value is false, i.e. do not allow.

See Section 4.5.5 of the JSR 380 specification, specifically

"One must not mark a method return value for cascaded validation more than once in a line of a class hierarchy.
In other words, overriding methods on sub types (be it sub classes/interfaces or interface implementations)
cannot mark the return value for cascaded validation if the return value has already been marked on the
overridden method of the super type or interface."
Parameters
allow:boolean

flag determining whether validation will allow multiple cascaded validation on return values.

Returns:HibernateValidatorContext

this following the chaining method pattern

Since
5.3
allowOverridingMethodAlterParameterConstraintback to summary
public HibernateValidatorContext allowOverridingMethodAlterParameterConstraint(boolean allow)

Define whether overriding methods that override constraints should throw a ConstraintDefinitionException. The default value is false, i.e. do not allow.

See Section 4.5.5 of the JSR 380 specification, specifically

"In sub types (be it sub classes/interfaces or interface implementations), no parameter constraints may
be declared on overridden or implemented methods, nor may parameters be marked for cascaded validation.
This would pose a strengthening of preconditions to be fulfilled by the caller."
Parameters
allow:boolean

flag determining whether validation will allow overriding to alter parameter constraints.

Returns:HibernateValidatorContext

this following the chaining method pattern

Since
5.3
allowParallelMethodsDefineParameterConstraintsback to summary
public HibernateValidatorContext allowParallelMethodsDefineParameterConstraints(boolean allow)

Define whether parallel methods that define constraints should throw a ConstraintDefinitionException. The default value is false, i.e. do not allow.

See Section 4.5.5 of the JSR 380 specification, specifically

"If a sub type overrides/implements a method originally defined in several parallel types of the hierarchy
(e.g. two interfaces not extending each other, or a class and an interface not implemented by said class),
no parameter constraints may be declared for that method at all nor parameters be marked for cascaded validation.
This again is to avoid an unexpected strengthening of preconditions to be fulfilled by the caller."
Parameters
allow:boolean

flag determining whether validation will allow parameter constraints in parallel hierarchies

Returns:HibernateValidatorContext

this following the chaining method pattern

Since
5.3
clockProviderback to summary
public HibernateValidatorContext clockProvider(ClockProvider clockProvider)

Redeclares jakarta.validation.ValidatorContext.clockProvider.

Doc from jakarta.validation.ValidatorContext.clockProvider.

Defines the ClockProvider implementation used by the Validator. If not set or if null is passed as a parameter, the clock provider of the ValidatorFactory is used.

Parameters
clockProvider:ClockProvider

ClockProvider implementation

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override
Since
6.0
constraintValidatorFactoryback to summary
public HibernateValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory)

Redeclares jakarta.validation.ValidatorContext.constraintValidatorFactory.

Doc from jakarta.validation.ValidatorContext.constraintValidatorFactory.

Defines the constraint validator factory implementation used by the Validator. If not set or if null is passed as a parameter, the constraint validator factory of the ValidatorFactory is used.

Parameters
factory:ConstraintValidatorFactory

the ConstraintValidatorFactory used by the Validator

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override
constraintValidatorPayloadback to summary
public HibernateValidatorContext constraintValidatorPayload(Object constraintValidatorPayload)

Define a payload passed to the constraint validators. If the method is called multiple times, only the payload passed last will be propagated.

Parameters
constraintValidatorPayload:Object

the payload passed to constraint validators

Returns:HibernateValidatorContext

this following the chaining method pattern

Annotations
@Incubating
Since
6.0.8
enableTraversableResolverResultCacheback to summary
public HibernateValidatorContext enableTraversableResolverResultCache(boolean enabled)

Define whether the per validation call caching of TraversableResolver results is enabled. The default value is true, i.e. the caching is enabled.

This behavior was initially introduced to cache the JPATraversableResolver results but the map lookups it introduces can be counterproductive when the TraversableResolver calls are very fast.

Parameters
enabled:boolean

flag determining whether per validation call caching is enabled for TraversableResolver results.

Returns:HibernateValidatorContext

this following the chaining method pattern

Since
6.0.3
failFastback to summary
public HibernateValidatorContext failFast(boolean failFast)

En- or disables the fail fast mode. When fail fast is enabled the validation will stop on the first constraint violation detected.

Parameters
failFast:boolean

true to enable fail fast, false otherwise.

Returns:HibernateValidatorContext

this following the chaining method pattern

messageInterpolatorback to summary
public HibernateValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)

Redeclares jakarta.validation.ValidatorContext.messageInterpolator.

Doc from jakarta.validation.ValidatorContext.messageInterpolator.

Defines the message interpolator implementation used by the Validator.

If not set or if null is passed as a parameter, the message interpolator of the ValidatorFactory is used.

Parameters
messageInterpolator:MessageInterpolator

the MessageInterpolator used by the Validator

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override
parameterNameProviderback to summary
public HibernateValidatorContext parameterNameProvider(ParameterNameProvider parameterNameProvider)

Redeclares jakarta.validation.ValidatorContext.parameterNameProvider.

Doc from jakarta.validation.ValidatorContext.parameterNameProvider.

Defines the parameter name provider implementation used by the Validator. If not set or if null is passed as a parameter, the parameter name provider of the ValidatorFactory is used.

Parameters
parameterNameProvider:ParameterNameProvider

parameter name provider implementation.

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override
Since
5.2
showValidatedValuesInTraceLogsback to summary
public HibernateValidatorContext showValidatedValuesInTraceLogs(boolean enabled)

Define whether values that are currently being validated should be part of the logging at trace level, or not.

Parameters
enabled:boolean

true to show the values at trace level, false otherwise.

Returns:HibernateValidatorContext

this following the chaining method pattern

Annotations
@Incubating
Since
8.0
temporalValidationToleranceback to summary
public HibernateValidatorContext temporalValidationTolerance(Duration temporalValidationTolerance)

Define the temporal validation tolerance i.e. the acceptable margin of error when comparing date/time in temporal constraints.

Parameters
temporalValidationTolerance:Duration

the tolerance

Returns:HibernateValidatorContext

this following the chaining method pattern

Annotations
@Incubating
Since
6.0.5
traversableResolverback to summary
public HibernateValidatorContext traversableResolver(TraversableResolver traversableResolver)

Redeclares jakarta.validation.ValidatorContext.traversableResolver.

Doc from jakarta.validation.ValidatorContext.traversableResolver.

Defines the traversable resolver implementation used by the Validator.

If not set or if null is passed as a parameter, the traversable resolver of the ValidatorFactory is used.

Parameters
traversableResolver:TraversableResolver

the TraversableResolver used by the Validator

Returns:HibernateValidatorContext

self following the chaining method pattern

Annotations
@Override