hibernate/hibernate-orm · error · HibernateException

Could not locate method needed for ValidatorFactory validati

Error message

Could not locate method needed for ValidatorFactory validation

What it means

After loading TypeSafeActivator, Hibernate looks up validateSuppliedFactory(Object) via reflection; any non-Hibernate failure of that lookup is wrapped as this HibernateException. In practice it means the TypeSafeActivator class that was loaded does not have the expected method — i.e. the class came from a different (older or duplicated) hibernate-core than the BeanValidationIntegrator calling it.

Source

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

						activatorClass.getMethod( VALIDATE_SUPPLIED_FACTORY_METHOD_NAME, Object.class );
				try {
					validateMethod.invoke( null, object );
				}
				catch (InvocationTargetException e) {
					if ( e.getTargetException() instanceof HibernateException exception ) {
						throw exception;
					}
					throw new HibernateException( "Unable to check validity of passed ValidatorFactory", e );
				}
				catch (IllegalAccessException e) {
					throw new HibernateException( "Unable to check validity of passed ValidatorFactory", e );
				}
			}
			catch (HibernateException e) {
				throw e;
			}
			catch (Exception e) {
				throw new HibernateException( "Could not locate method needed for ValidatorFactory validation", e );
			}
		}
		catch (HibernateException e) {
			throw e;
		}
		catch (Exception e) {
			throw new HibernateException( "Could not locate TypeSafeActivator class", e );
		}
	}

	@Override
	public void integrate(
			Metadata metadata,
			Integrator.Context context,
			SessionFactoryImplementor sessionFactory) {
		final var serviceRegistry = sessionFactory.getServiceRegistry();
		// IMPL NOTE: see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
		final var modes = getValidationModes( serviceRegistry );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Run mvn dependency:tree / gradle dependencies and remove the duplicate hibernate-core
  2. Pin exactly one hibernate-core version with dependencyManagement / constraints
  3. Verify the final artifact (unzip the fat jar) contains exactly one org/hibernate/boot/beanvalidation/TypeSafeActivator.class
Defensive patterns

Strategy: validation

Validate before calling

// detect duplicate hibernate-core artifacts before bootstrap
static void assertSingleHibernateCore() throws IOException {
    Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(
        "org/hibernate/boot/beanvalidation/BeanValidationIntegrator.class");
    List<URL> found = Collections.list(urls);
    if (found.size() > 1)
        throw new IllegalStateException("Multiple hibernate-core copies on classpath: " + found);
}

Try / catch

try {
    emf = Persistence.createEntityManagerFactory("pu", props);
} catch (HibernateException e) {
    if (e.getMessage().contains("Could not locate method needed for ValidatorFactory validation"))
        throw new IllegalStateException("Duplicate/stale hibernate-core detected; run dependency:tree and dedupe", e);
    throw e;
}

Prevention

When it happens

Trigger: Two different hibernate-core versions on the classpath (one stale, shaded, or pinned transitively) while a supplied ValidatorFactory triggers the validity check, so the reflective getMethod finds no matching signature.

Common situations: Fat jars accidentally bundling an extra hibernate-core; dependency management pinning an old version while a framework BOM pulls a newer one; shaded assemblies not rebuilt after an upgrade.

Related errors


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