{"record":{"id":"068e2a39c6eabd4d","repo":"hibernate/hibernate-orm","slug":"unable-to-check-validity-of-passed-validatorfactor","errorCode":null,"errorMessage":"Unable to check validity of passed ValidatorFactory","messagePattern":"Unable to check validity of passed ValidatorFactory","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java","lineNumber":67,"sourceCode":"\t * @param object The supposed ValidatorFactory instance\n\t */\n\tpublic static void validateFactory(Object object) {\n\t\ttry {\n\t\t\t// this direct usage of ClassLoader should be fine since the classes exist in the same jar\n\t\t\tfinal var activatorClass =\n\t\t\t\t\tBeanValidationIntegrator.class.getClassLoader()\n\t\t\t\t\t\t\t.loadClass( ACTIVATOR_CLASS_NAME );\n\t\t\ttry {\n\t\t\t\tfinal var validateMethod =\n\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}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationIntegrator.java#L49-L85","documentation":"When a ValidatorFactory is supplied to Hibernate (e.g. via the jakarta.persistence.validation.factory property), Hibernate reflectively calls TypeSafeActivator.validateSuppliedFactory to verify it. If that reflective invocation throws an InvocationTargetException whose target is not a HibernateException, the target is wrapped in this HibernateException — the supplied object itself exploded during the check, most often a linkage failure from mixed validation API versions.","triggerScenarios":"Passing a ValidatorFactory through persistence unit properties while the javax/jakarta validation API and provider jars on the classpath are inconsistent, so merely touching the factory triggers NoClassDefFoundError/LinkageError inside the reflective call; also seen under classloader domains that partially isolate the provider.","commonSituations":"Partial Spring Boot 2→3 / Java EE→Jakarta migrations leaving both javax.validation and jakarta.validation artifacts; a ValidatorFactory built by a different, incompatible classloader (app server vs WAR).","solutions":["Unwrap and read the nested cause (commonly NoClassDefFoundError or LinkageError) and remove the conflicting validation jar it names","Align the whole stack on one namespace and one provider generation (e.g. hibernate-validator 8.x + jakarta.validation-api 3.x)","Build the ValidatorFactory inside the same deployment/classloader as Hibernate","Prefer letting Hibernate bootstrap its own factory: drop the supplied-factory property"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// refuse to boot with both validation namespaces present\nstatic void assertSingleValidationNamespace() {\n    boolean javaxApi   = present(\"javax.validation.Validation\");\n    boolean jakartaApi = present(\"jakarta.validation.Validation\");\n    if (javaxApi && jakartaApi)\n        throw new IllegalStateException(\n            \"Both javax and jakarta validation APIs on the classpath; remove one before passing a ValidatorFactory\");\n}\n\nstatic boolean present(String cn) {\n    try { Class.forName(cn, false, Thread.currentThread().getContextClassLoader()); return true; }\n    catch (ClassNotFoundException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props); // props contain validation.factory\n} catch (HibernateException e) {\n    Throwable root = e;\n    while (root.getCause() != null) root = root.getCause();\n    // root is often NoClassDefFoundError naming the conflicting validation jar\n    throw new IllegalStateException(\"Supplied ValidatorFactory failed validation check; cause: \" + root, e);\n}","preventionTips":["Run one consistent validation namespace/provider across all modules","Build the factory you pass with the same classloader as the application"],"tags":["hibernate","bean-validation","classloader","jaxb-no","dependency-conflict"],"backgroundTag":"classpath-dependency-conflict","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}