{"record":{"id":"b5b69042ac6f17f0","repo":"hibernate/hibernate-orm","slug":"could-not-instantiate-type","errorCode":null,"errorMessage":"Could not instantiate type","messagePattern":"Could not instantiate type","errorType":"exception","errorClass":"InstantiationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/TypeBeanInstanceProducer.java","lineNumber":42,"sourceCode":"public class TypeBeanInstanceProducer implements BeanInstanceProducer, TypeBootstrapContext {\n\tprivate final ConfigurationService configurationService;\n\tprivate final ServiceRegistry serviceRegistry;\n\n\tpublic TypeBeanInstanceProducer(ConfigurationService configurationService, ServiceRegistry serviceRegistry) {\n\t\tthis.configurationService = configurationService;\n\t\tthis.serviceRegistry = serviceRegistry;\n\t}\n\n\t@Override\n\tpublic <B> B produceBeanInstance(Class<B> beanType) {\n\t\tfinal var bootstrapContextAwareConstructor =\n\t\t\t\tgetConstructorOrNull( beanType, TypeBootstrapContext.class );\n\t\tif ( bootstrapContextAwareConstructor != null ) {\n\t\t\ttry {\n\t\t\t\treturn bootstrapContextAwareConstructor.newInstance( this );\n\t\t\t}\n\t\t\tcatch ( Exception e ) {\n\t\t\t\tthrow new InstantiationException( \"Could not instantiate type\", beanType, e );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tfinal var constructor = getConstructorOrNull( beanType );\n\t\t\tif ( constructor != null ) {\n\t\t\t\ttry {\n\t\t\t\t\treturn constructor.newInstance();\n\t\t\t\t}\n\t\t\t\tcatch ( Exception e ) {\n\t\t\t\t\tthrow new InstantiationException( \"Could not instantiate type\", beanType, e );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new InstantiationException( \"No appropriate constructor for type\", beanType );\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/TypeBeanInstanceProducer.java#L24-L60","documentation":"Error \"Could not instantiate type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"CDI-style bean creation of a custom Hibernate type fails.","commonSituations":"A custom UserType/AttributeConverter bean that cannot be instantiated, lacking an injectable or no-arg constructor.","solutions":["Check the causal exception: the type class failed to instantiate, typically due to a missing no-arg constructor or a constructor throwing.","Ensure the custom type class is public, non-abstract, and has an accessible constructor.","Verify the correct class name is registered for the TypeDefinition."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}