{"record":{"id":"04e38ac4969c6a53","repo":"hibernate/hibernate-orm","slug":"given-object-was-not-an-instance-of","errorCode":null,"errorMessage":"Given object was not an instance of {} [{}]","messagePattern":"Given object was not an instance of (.+?) \\[(.+?)\\]","errorType":"exception","errorClass":"IntegrationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java","lineNumber":88,"sourceCode":"\n/**\n * Sets up Bean Validation {@linkplain BeanValidationEventListener event listener} and DDL-based constraints.\n *\n * @author Emmanuel Bernard\n * @author Hardy Ferentschik\n * @author Steve Ebersole\n */\nclass TypeSafeActivator {\n\n\t/**\n\t * Used to validate a supplied ValidatorFactory instance as being castable to ValidatorFactory.\n\t *\n\t * @param object The supplied ValidatorFactory instance.\n\t */\n\t@SuppressWarnings(\"unused\")\n\tpublic static void validateSuppliedFactory(Object object) {\n\t\tif ( !(object instanceof ValidatorFactory) ) {\n\t\t\tthrow new IntegrationException( \"Given object was not an instance of \" + ValidatorFactory.class.getName()\n\t\t\t\t\t\t\t+ \" [\" + object.getClass().getName() + \"]\" );\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tpublic static void activate(ActivationContext context) {\n\t\tfinal ValidatorFactory factory;\n\t\ttry {\n\t\t\tfactory = getValidatorFactory( context );\n\t\t}\n\t\tcatch (IntegrationException exception) {\n\t\t\tif ( context.getValidationModes().contains( ValidationMode.CALLBACK ) ) {\n\t\t\t\tthrow new IntegrationException( \"Jakarta Validation provider was not available, but 'callback' validation mode was requested\", exception );\n\t\t\t}\n\t\t\telse if ( context.getValidationConstraintDdlInfluence() == ValidationConstraintDdlInfluence.REQUIRED ) {\n\t\t\t\tthrow new IntegrationException( \"Jakarta Validation provider was not available, but '\"\n\t\t\t\t\t\t+ APPLY_VALIDATION_CONSTRAINTS + \"' was resolved to 'REQUIRED'\", exception );\n\t\t\t}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"Spring Boot 2→3 migrations; legacy @Bean producers still typed to javax.validation; copy-pasted configuration from older tutorials.","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"],"exampleFix":"// before (javax factory on a Jakarta stack)\nprops.put(\"jakarta.persistence.validation.factory\", javaxValidatorFactory);\n\n// after\nprops.put(\"jakarta.persistence.validation.factory\",\n          jakarta.validation.Validation.buildDefaultValidatorFactory());","handlingStrategy":"type-guard","validationCode":"// check before putting the property into persistence unit settings\nObject candidate = factoryBean;\nif (!(candidate instanceof jakarta.validation.ValidatorFactory))\n    throw new IllegalArgumentException(\n        \"validation.factory must be a jakarta.validation.ValidatorFactory, got \"\n        + (candidate == null ? \"null\" : candidate.getClass().getName()));\nsettings.put(\"jakarta.persistence.validation.factory\", candidate);","typeGuard":"static jakarta.validation.ValidatorFactory asJakartaFactory(Object candidate) {\n    if (candidate instanceof jakarta.validation.ValidatorFactory factory) return factory;\n    throw new IllegalArgumentException(\n        \"Wrong factory type (javax/jakarta mismatch?): \" + candidate.getClass().getName());\n}","tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\", props);\n} catch (IntegrationException e) {\n    if (e.getMessage().startsWith(\"Given object was not an instance of\"))\n        throw new IllegalStateException(\n            \"Passed factory is from the wrong namespace/type; supply jakarta.validation.ValidatorFactory\", e);\n    throw e;\n}","preventionTips":["After Jakarta migration, grep for javax.validation producers and the validation.factory property","Let Hibernate build its own ValidatorFactory unless injection is required"],"tags":["hibernate","bean-validation","validatorfactory","jakarta-migration","type-mismatch"],"backgroundTag":"javax-jakarta-namespace-conflict","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}