hibernate/hibernate-orm · error · IntegrationException

Jakarta Validation API was not available, but 'callback' val

Error message

Jakarta Validation API was not available, but 'callback' validation was requested

What it means

At integration time Hibernate detected that the Jakarta Validation API is absent from the classpath, but the persistence unit requested CALLBACK validation (validation-mode in persistence.xml or the jakarta.persistence.validation.mode setting). Since Hibernate cannot honor callbacks without the API, it fails fast during SessionFactory construction.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java:176

	private boolean isBeanValidationApiAvailable(ClassLoaderService classLoaderService) {
		try {
			classLoaderService.classForName( JAKARTA_BV_CHECK_CLASS );
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}

	/**
	 * Used to validate the case when the Jakarta Validation API is not available.
	 *
	 * @param modes The requested validation modes.
	 */
	private void validateMissingBeanValidationApi(Set<ValidationMode> modes, ValidationConstraintDdlInfluence constraintInfluence) {
		if ( modes.contains( ValidationMode.CALLBACK ) ) {
			throw new IntegrationException( "Jakarta Validation API was not available, but 'callback' validation was requested" );
		}
		if ( constraintInfluence == ValidationConstraintDdlInfluence.REQUIRED ) {
			throw new IntegrationException( "Bean Validation API was not available, but '"
					+ SchemaToolingSettings.APPLY_VALIDATION_CONSTRAINTS + "' was set to 'REQUIRED'" );
		}
	}

	private Class<?> loadTypeSafeActivatorClass(ClassLoaderService classLoaderService) {
		try {
			return classLoaderService.classForName( ACTIVATOR_CLASS_NAME );
		}
		catch (Exception e) {
			throw new HibernateException( "Unable to load TypeSafeActivator class", e );
		}
	}

	private record ActivationContextImpl(
			Set<ValidationMode> modes,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add jakarta.validation:jakarta.validation-api plus a provider such as hibernate-validator
  2. If entity validation is unwanted, change validation mode to NONE
  3. Verify the runtime classpath (docker image, assembly, shaded jar) actually contains the API jar

Example fix

// before: persistence.xml requests callbacks, classpath lacks the API
<validation-mode>CALLBACK</validation-mode>

// after: add API + provider to the runtime classpath (pom.xml)
<dependency>
  <groupId>jakarta.validation</groupId>
  <artifactId>jakarta.validation-api</artifactId>
  <version>3.0.2</version>
</dependency>
<dependency>
  <groupId>org.hibernate.validator</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>8.0.1.Final</version>
</dependency>
Defensive patterns

Strategy: validation

Validate before calling

// check the API is really on the runtime classpath before requesting CALLBACK
try {
    Class.forName("jakarta.validation.ValidatorFactory", false,
                  Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
    // either add jakarta.validation-api + provider, or change validation-mode to NONE
    throw new IllegalStateException("CALLBACK requested but jakarta.validation-api is missing", e);
}

Try / catch

try {
    emf = Persistence.createEntityManagerFactory("pu");
} catch (IntegrationException e) {
    if (e.getMessage().contains("'callback' validation was requested"))
        throw new IllegalStateException("Add jakarta.validation-api + a provider, or set validation-mode NONE", e);
    throw e;
}

Prevention

When it happens

Trigger: persistence.xml with <validation-mode>CALLBACK</validation-mode> or the property jakarta.persistence.validation.mode=callback while jakarta.validation:jakarta.validation-api is not on the runtime classpath.

Common situations: Dependencies slimmed to scope provided but missing at runtime; persistence.xml templates copied from a Java EE app into plain Java SE; fat-jar minimization (ProGuard, shade rules) stripping 'unused' validation jars.

Related errors


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