hibernate/hibernate-orm · error · IntegrationException
Given object was not an instance of {} [{}]
Error message
Given object was not an instance of {} [{}] What it means
TypeSafeActivator.validateSuppliedFactory checks the object passed as the ValidatorFactory (the jakarta.persistence.validation.factory property). If it is not an instance of jakarta.validation.ValidatorFactory, this IntegrationException names the expected interface and the actual class. On a Jakarta-era Hibernate the classic cause is passing a javax.validation.ValidatorFactory left over from a pre-migration stack.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java:88
/**
* Sets up Bean Validation {@linkplain BeanValidationEventListener event listener} and DDL-based constraints.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
* @author Steve Ebersole
*/
class TypeSafeActivator {
/**
* Used to validate a supplied ValidatorFactory instance as being castable to ValidatorFactory.
*
* @param object The supplied ValidatorFactory instance.
*/
@SuppressWarnings("unused")
public static void validateSuppliedFactory(Object object) {
if ( !(object instanceof ValidatorFactory) ) {
throw new IntegrationException( "Given object was not an instance of " + ValidatorFactory.class.getName()
+ " [" + object.getClass().getName() + "]" );
}
}
@SuppressWarnings("unused")
public static void activate(ActivationContext context) {
final ValidatorFactory factory;
try {
factory = getValidatorFactory( context );
}
catch (IntegrationException exception) {
if ( context.getValidationModes().contains( ValidationMode.CALLBACK ) ) {
throw new IntegrationException( "Jakarta Validation provider was not available, but 'callback' validation mode was requested", exception );
}
else if ( context.getValidationConstraintDdlInfluence() == ValidationConstraintDdlInfluence.REQUIRED ) {
throw new IntegrationException( "Jakarta Validation provider was not available, but '"
+ APPLY_VALIDATION_CONSTRAINTS + "' was resolved to 'REQUIRED'", exception );
}View on GitHub (pinned to fad1729dce)
Solutions
- Supply a jakarta.validation.ValidatorFactory (built e.g. by Validation.buildDefaultValidatorFactory())
- Update the producing bean/framework to the Jakarta namespace generation
- Remove the property entirely and let Hibernate bootstrap its own factory
Example fix
// before (javax factory on a Jakarta stack)
props.put("jakarta.persistence.validation.factory", javaxValidatorFactory);
// after
props.put("jakarta.persistence.validation.factory",
jakarta.validation.Validation.buildDefaultValidatorFactory()); Defensive patterns
Strategy: type-guard
Validate before calling
// check before putting the property into persistence unit settings
Object candidate = factoryBean;
if (!(candidate instanceof jakarta.validation.ValidatorFactory))
throw new IllegalArgumentException(
"validation.factory must be a jakarta.validation.ValidatorFactory, got "
+ (candidate == null ? "null" : candidate.getClass().getName()));
settings.put("jakarta.persistence.validation.factory", candidate); Type guard
static jakarta.validation.ValidatorFactory asJakartaFactory(Object candidate) {
if (candidate instanceof jakarta.validation.ValidatorFactory factory) return factory;
throw new IllegalArgumentException(
"Wrong factory type (javax/jakarta mismatch?): " + candidate.getClass().getName());
} Try / catch
try {
emf = Persistence.createEntityManagerFactory("pu", props);
} catch (IntegrationException e) {
if (e.getMessage().startsWith("Given object was not an instance of"))
throw new IllegalStateException(
"Passed factory is from the wrong namespace/type; supply jakarta.validation.ValidatorFactory", e);
throw e;
} Prevention
- After Jakarta migration, grep for javax.validation producers and the validation.factory property
- Let Hibernate build its own ValidatorFactory unless injection is required
When it happens
Trigger: Setting the validation.factory property to an object of the wrong type — typically a javax.validation.ValidatorFactory on Hibernate 6+/Jakarta, a Spring LocalValidatorFactoryBean from an old Spring generation, or an unrelated bean wired into the property by mistake.
Common situations: Spring Boot 2→3 migrations; legacy @Bean producers still typed to javax.validation; copy-pasted configuration from older tutorials.
Related errors
- Error activating Bean Validation integration
- jakarta.persistence.validation.group.{} is of unknown type:
- Validation failed for classes {} during {} time for groups [
- Unable to check validity of passed ValidatorFactory
- Unable to locate TypeSafeActivator#activate method
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/04e38ac4969c6a53.
Report an issue: GitHub.