hibernate/hibernate-orm · error · IntegrationException

ValidatorFactory reference (provided via %s) was not castabl

Error message

ValidatorFactory reference (provided via %s) was not castable to %s : %s

What it means

Error "ValidatorFactory reference (provided via %s) was not castable to %s : %s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java:689

		// 3 - build our own
		try {
			return Validation.buildDefaultValidatorFactory();
		}
		catch ( Exception e ) {
			throw new IntegrationException( "Unable to build the default ValidatorFactory", e );
		}
	}

	private static ValidatorFactory resolveProvidedFactory(SessionFactoryOptions options) {
		final Object validatorFactoryReference = options.getValidatorFactoryReference();
		if ( validatorFactoryReference == null ) {
			return null;
		}
		else if ( validatorFactoryReference instanceof ValidatorFactory result ) {
			return result;
		}
		else {
			throw new IntegrationException(
					String.format(
							Locale.ENGLISH,
							"ValidatorFactory reference (provided via %s) was not castable to %s : %s",
							SessionFactoryOptions.class.getName(),
							ValidatorFactory.class.getName(),
							validatorFactoryReference.getClass().getName()
					)
			);
		}
	}

	private static ValidatorFactory resolveProvidedFactory(ConfigurationService cfgService) {
		final var jakartaValidationFactory = cfgService.getSetting(
				JAKARTA_VALIDATION_FACTORY,
				value -> validatorFactory( value, JAKARTA_VALIDATION_FACTORY )
		);
		if ( jakartaValidationFactory != null ) {
			return jakartaValidationFactory;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Check the object bound under the jakarta.persistence.validation.factory setting; it must implement jakarta.validation.ValidatorFactory.
  2. Make sure the ValidatorFactory was created by the same Jakarta Validation API version on the classpath (do not mix javax.validation and jakarta.validation artifacts).
  3. Pass the ValidatorFactory instance directly as a property value instead of a JNDI name or string.

When it happens

Trigger: The ValidatorFactory supplied via configuration is of an incompatible type.

Common situations: Passing a non-jakarta ValidatorFactory (e.g. the old javax.validation one) through jakarta.persistence.validation.factory or a JNDI-bound factory after the javax-to-jakarta migration.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/8bcfe69cefc55527. Report an issue: GitHub.