JakartaKandraValidator

class JakartaKandraValidator<T : Any>(validator: Validator = sharedValidatorFactory.validator) : KandraValidator<T>

Adapts a jakarta.validation.Validator into a KandraValidator, running Jakarta Bean Validation constraints (@NotNull, @Size, etc.) declared on an entity's fields before every save/update.

Requires a Bean Validation implementation (e.g. Hibernate Validator) on the runtime classpath — jakarta.validation-api is a compileOnly dependency of this module, so bring your own implementation alongside it.

The default Validator comes from sharedValidatorFactory — a single lazily-built, process-wide ValidatorFactory shared by every default-constructed instance (GH-36). Kandra's validate<T> { } config block registers one JakartaKandraValidator per entity type, and Validation.buildDefaultValidatorFactory() is relatively expensive (classpath scanning + constraint metadata resolution) and returns a Closeable resource — building one per entity type instead of sharing a single factory meant an app validating N entity types built and leaked N separate factories. Validator instances obtained from a ValidatorFactory are documented as thread-safe and stateless, so sharing one across every entity's validator is safe.

Constructors

Link copied to clipboard
constructor(validator: Validator = sharedValidatorFactory.validator)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun validate(entity: T): List<KandraValidationError>