{"record":{"id":"234d833f47f6d688","repo":"hibernate/hibernate-orm","slug":"could-not-locate-method-needed-for-validatorfactor","errorCode":null,"errorMessage":"Could not locate method needed for ValidatorFactory validation","messagePattern":"Could not locate method needed for ValidatorFactory validation","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java","lineNumber":77,"sourceCode":"\t\t\t\t\t\tactivatorClass.getMethod( VALIDATE_SUPPLIED_FACTORY_METHOD_NAME, Object.class );\n\t\t\t\ttry {\n\t\t\t\t\tvalidateMethod.invoke( null, object );\n\t\t\t\t}\n\t\t\t\tcatch (InvocationTargetException e) {\n\t\t\t\t\tif ( e.getTargetException() instanceof HibernateException exception ) {\n\t\t\t\t\t\tthrow exception;\n\t\t\t\t\t}\n\t\t\t\t\tthrow new HibernateException( \"Unable to check validity of passed ValidatorFactory\", e );\n\t\t\t\t}\n\t\t\t\tcatch (IllegalAccessException e) {\n\t\t\t\t\tthrow new HibernateException( \"Unable to check validity of passed ValidatorFactory\", e );\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (HibernateException e) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new HibernateException( \"Could not locate method needed for ValidatorFactory validation\", e );\n\t\t\t}\n\t\t}\n\t\tcatch (HibernateException e) {\n\t\t\tthrow e;\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new HibernateException( \"Could not locate TypeSafeActivator class\", e );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void integrate(\n\t\t\tMetadata metadata,\n\t\t\tIntegrator.Context context,\n\t\t\tSessionFactoryImplementor sessionFactory) {\n\t\tfinal var serviceRegistry = sessionFactory.getServiceRegistry();\n\t\t// IMPL NOTE: see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...\n\t\tfinal var modes = getValidationModes( serviceRegistry );","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run mvn dependency:tree / gradle dependencies and remove the duplicate hibernate-core","Pin exactly one hibernate-core version with dependencyManagement / constraints","Verify the final artifact (unzip the fat jar) contains exactly one org/hibernate/boot/beanvalidation/TypeSafeActivator.class"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// detect duplicate hibernate-core artifacts before bootstrap\nstatic void assertSingleHibernateCore() throws IOException {\n    Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(\n        \"org/hibernate/boot/beanvalidation/BeanValidationIntegrator.class\");\n    List<URL> found = Collections.list(urls);\n    if (found.size() > 1)\n        throw new IllegalStateException(\"Multiple hibernate-core copies on classpath: \" + found);\n}","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props);\n} catch (HibernateException e) {\n    if (e.getMessage().contains(\"Could not locate method needed for ValidatorFactory validation\"))\n        throw new IllegalStateException(\"Duplicate/stale hibernate-core detected; run dependency:tree and dedupe\", e);\n    throw e;\n}","preventionTips":["Enforce a single hibernate-core version via BOM/dependencyManagement","When shading, verify the output jar contains each Hibernate class exactly once"],"tags":["hibernate","dependency-conflict","classloader","version-mismatch"],"backgroundTag":"dependency-version-conflict","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}